Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. FileSystemWritableFileStream
  4. seek()

FileSystemWritableFileStream: seek() method

Baseline 2025
Newly available

Since September 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

Theseek() method of theFileSystemWritableFileStream interface updates the current file cursor offset to the position (in bytes) specified when calling the method.

Syntax

js
seek(position)

Parameters

position

A number specifying the byte position from the beginning of the file.

Return value

APromise that returnsundefined.

Exceptions

NotAllowedErrorDOMException

Thrown ifPermissionStatus.state is notgranted.

TypeError

Thrown ifposition is not a number or not defined.

Examples

The following asynchronous function opens the 'Save File' picker, which returns aFileSystemFileHandle once a file is selected. From this, a writable stream is created using theFileSystemFileHandle.createWritable() method.

Next, we write to the stream:

  1. A text string is written to the stream.
  2. Theseek() method is used to put the cursor at the start of the stream.
  3. A second text string is written to the start of the stream, overwriting the first write.

The stream is then closed.

js
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".

Specifications

Specification
File System
# api-filesystemwritablefilestream-seek

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp