← Back to release summary

Seeking past the end of a file in the File System Access API

Category
File APIs
Type
No developer-visible change
Status
Enabled by default (Chrome 90)
Intent stage
Shipped

Summary

Rather than rejecting when trying to write past the end of a file, require extending a file with some number of 0x00 (NUL) bytes instead. This enables creating sparse files and greatly simplifies saving content to a file when the data to be written is received out of order.

Motivation

Without this functionality, applications which receive file contents out of order (ex: bittorrent downloads) would have to manually make sure to resize the file either ahead of time or when needed during writing. The behavior here would have already been possible by keeping track of the file size, and inserting appropriate truncate() calls to grow the file whenever trying to write past the end of a file. Not requiring these explicit truncate calls simplifies code, and reduces the chance of bugs in websites (accidentally shrinking files when they don't need to, for example).

Standards & signals

Explainers: https://github.com/WICG/file-system-access/pull/266

View on chromestatus.com