Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. FileSystemWritableFileStream

FileSystemWritableFileStream

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.

TheFileSystemWritableFileStream interface of theFile System API is aWritableStream object with additional convenience methods, which operates on a single file on disk. The interface is accessed through theFileSystemFileHandle.createWritable() method.

WritableStream FileSystemWritableFileStream

Instance properties

Inherits properties from its parent,WritableStream.

Instance methods

Inherits methods from its parent,WritableStream.

FileSystemWritableFileStream.write()

Writes content into the file the method is called on, at the current file cursor offset.

FileSystemWritableFileStream.seek()

Updates the current file cursor offset to the position (in bytes) specified.

FileSystemWritableFileStream.truncate()

Resizes the file associated with the stream to be the specified size in bytes.

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.

A text string is then written to the stream, which is subsequently closed.

js
async function saveFile() {  // 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("This is my file content");  // close the file and write the contents to disk.  await writableStream.close();}

The following examples show different options that can be passed into thewrite() method.

js
// just pass in the data (no options)writableStream.write(data);// writes the data to the stream from the determined positionwritableStream.write({ type: "write", position, data });// updates the current file cursor offset to the position specifiedwritableStream.write({ type: "seek", position });// resizes the file to be size bytes longwritableStream.write({ type: "truncate", size });

Specifications

Specification
File System
# api-filesystemwritablefilestream

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp