You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: files/en-us/web/api/filesystemwritablefilestream/index.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,10 @@
2
2
title: FileSystemWritableFileStream
3
3
slug: Web/API/FileSystemWritableFileStream
4
4
page-type: web-api-interface
5
-
status:
6
-
- experimental
7
5
browser-compat: api.FileSystemWritableFileStream
8
6
---
9
7
10
-
{{securecontext_header}}{{APIRef("File System Access API")}}{{SeeCompatTable}}
8
+
{{securecontext_header}}{{APIRef("File System Access API")}}
11
9
12
10
The **`FileSystemWritableFileStream`** interface of the {{domxref('File System Access API')}} is a {{domxref('WritableStream')}} object with additional convenience methods, which operates on a single file on disk. The interface is accessed through the {{domxref('FileSystemFileHandle.createWritable()')}} method.
13
11
@@ -21,11 +19,11 @@ _Inherits properties from its parent, {{DOMxRef("WritableStream")}}._
21
19
22
20
_Inherits methods from its parent, {{DOMxRef("WritableStream")}}._
{{securecontext_header}}{{APIRef("File System Access API")}}{{SeeCompatTable}}
8
+
{{securecontext_header}}{{APIRef("File System Access API")}}
11
9
12
-
The **`seek()`** method of the
13
-
{{domxref("FileSystemWritableFileStream")}} interface updates the current file cursor
14
-
offset to the position (in bytes) specified when calling the method.
10
+
The **`seek()`** method of the {{domxref("FileSystemWritableFileStream")}} interface updates the current file cursor offset to the position (in bytes) specified when calling the method.
{{securecontext_header}}{{APIRef("File System Access API")}}{{SeeCompatTable}}
8
+
{{securecontext_header}}{{APIRef("File System Access API")}}
11
9
12
-
The **`truncate()`** method of the
13
-
{{domxref("FileSystemWritableFileStream")}} interface resizes the file associated with
14
-
the stream to be the specified size in bytes.
10
+
The **`truncate()`** method of the {{domxref("FileSystemWritableFileStream")}} interface resizes the file associated with the stream to be the specified size in bytes.
15
11
16
-
If the size specified is larger than the current file size this pads the file with
17
-
`null` bytes, otherwise it truncates the file.
12
+
If the size specified is larger than the current file size this pads the file with `null` bytes, otherwise it truncates the file.
18
13
19
-
The file cursor is also updated when `truncate()` is called. If the offset
20
-
is smaller than the size, it remains unchanged. If the offset is larger than size, the
21
-
offset is set to that size. This ensures that subsequent writes do not error.
14
+
The file cursor is also updated when `truncate()` is called.
15
+
If the offset is smaller than the size, it remains unchanged.
16
+
If the offset is larger than size, the offset is set to that size.
17
+
This ensures that subsequent writes do not error.
22
18
23
19
No changes are written to the actual file on disk until the stream has been closed.
24
20
Changes are typically written to a temporary file instead.
{{securecontext_header}}{{APIRef("File System Access API")}}{{SeeCompatTable}}
8
+
{{securecontext_header}}{{APIRef("File System Access API")}}
11
9
12
-
The **`write()`** method of the
13
-
{{domxref("FileSystemWritableFileStream")}} interface writes content into the file the
14
-
method is called on, at the current file cursor offset.
10
+
The **`write()`** method of the {{domxref("FileSystemWritableFileStream")}} interface writes content into the file the method is called on, at the current file cursor offset.
15
11
16
12
No changes are written to the actual file on disk until the stream has been closed.
17
-
Changes are typically written to a temporary file instead. This method can also be used
18
-
to seek to a byte point within the stream and truncate to modify the total bytes the
19
-
file contains.
13
+
Changes are typically written to a temporary file instead. This method can also be used to seek to a byte point within the stream and truncate to modify the total bytes the file contains.
20
14
21
15
## Syntax
22
16
@@ -60,13 +54,10 @@ write(data)
60
54
61
55
## Examples
62
56
63
-
This asynchronous function opens the 'Save File' picker, which returns a
64
-
{{domxref('FileSystemFileHandle')}} once a file is selected. From which a writable
65
-
stream is then created using the {{domxref('FileSystemFileHandle.createWritable()')}}
66
-
method.
57
+
This asynchronous function opens the 'Save File' picker, which returns a {{domxref('FileSystemFileHandle')}} once a file is selected.
58
+
From which a writable stream is then created using the {{domxref('FileSystemFileHandle.createWritable()')}} method.
67
59
68
-
A user defined {{domxref('Blob')}} is then written to the stream which is subsequently
69
-
closed.
60
+
A user defined {{domxref('Blob')}} is then written to the stream which is subsequently closed.
70
61
71
62
```js
72
63
asyncfunctionsaveFile() {
@@ -84,8 +75,7 @@ async function saveFile() {
84
75
}
85
76
```
86
77
87
-
The following show different examples of options that can be passed into the
88
-
`write()` method.
78
+
The following show different examples of options that can be passed into the `write()` method.
0 commit comments