This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The seek() method of the FileSystemWritableFileStream interface updates the current file cursor offset to the position (in bytes) specified when calling the method.
seek(position)
positionA number specifying the byte position from the beginning of the file.
A Promise that returns undefined.
NotAllowedError DOMException
Thrown if PermissionStatus.state is not granted.
TypeErrorThrown if position is not a number or not defined.
The following asynchronous function opens the 'Save File' picker, which returns a FileSystemFileHandle once a file is selected. From this, a writable stream is created using the FileSystemFileHandle.createWritable() method.
Next, we write to the stream:
seek() method is used to put the cursor at the start of the stream.The stream is then closed.
async function saveFile() {
try {
// create a new handle
const newHandle = await window.showSaveFilePicker();
// create a FileSystemWritableFileStream to write to
const writableStream = await newHandle.createWritable();
// write our file
await writableStream.write("My first file content");
await writableStream.seek(0);
await writableStream.write("My second file content");
// close the file and write the contents to disk.
await writableStream.close();
} catch (err) {
console.error(err.name, err.message);
}
}
If you run the above function and then open the resulting file created on disk, you should see the text "My second file content".
| Specification |
|---|
| File System> # api-filesystemwritablefilestream-seek> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
seek |
86 | 86 | 111 | 72 | 26 | 109 | 111 | 74 | 26 | 21.0 | 109 | 26 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek