Rename filename.ext.crswap to filename.ext rather than copying

302 Views Asked by At

When performing this sequence

  • Obtain a handle to a new file via window.showSaveFilePicker, say filename.ext
  • Obtain a writeable file stream from the handle
  • Write some content into the file using the stream
  • close the stream to signal completion

the File System API writes to filename.ext.crswap and on close copies filename.ext.crswap to filename.ext

Is there a reason that filename.ext.crswap is not rather renamed to filename.ext?

1

There are 1 best solutions below

2
On

The reason for this behavior is to avoid partial writes:

"User agents try to ensure that no partial writes happen, i.e. the file represented by fileHandle will either contain its old contents or it will contain whatever data was written through stream up until the stream has been closed."Spec.