A user defined Blob is then written to the stream which is subsequently closed.
asyncfunctionsaveFile(){// create a new handleconst newHandle =await window.showSaveFilePicker();// create a FileSystemWritableFileStream to write toconst writableStream =await newHandle.createWritable();// write our fileawait writableStream.write(imgBlob);// close the file and write the contents to disk.await writableStream.close();}
The following show different examples of options that can be passed into the write() method.
// just pass in the data (no options)
writableStream.write(data);// writes the data to the stream from the determined position
writableStream.write({type:"write", position, data });// updates the current file cursor offset to the position specified
writableStream.write({type:"seek", position });// resizes the file to be size bytes long
writableStream.write({type:"truncate", size });