Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support seeking past the end of a file. #266

Merged
merged 1 commit into from
Feb 4, 2021

Conversation

mkruisselbrink
Copy link
Contributor

@mkruisselbrink mkruisselbrink commented Jan 20, 2021

Rather than rejecting when trying to write past the end of a file this
changes the spec to require extending a file with some number of
0x00 (NUL) bytes instead.

This enables creating sparse files (very useful for certain file formats
such as disk images). Additionally this greatly simplifies saving content
to a file when the data to be written is received out of order (such as in
the case of bittorrent downloads). Without this functionality such a
application would have to manually make sure to resize the file either
ahead of time or when needed during writing.

Note that 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).

This fixes #262


Preview | Diff

Copy link
Collaborator

@a-sully a-sully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Base automatically changed from master to main January 21, 2021 23:45
Rather than rejecting when trying to write past the end of a file this
changes the spec to require extending a file with 0 bytes instead.

This enables creating sparse files (very useful for certain file formats
such as disk images). Additionally this greatly simplifies saving content
to a file when the data to be written is received out of order (such as in
the case of bittorrent downloads). Without this functionality such a
application would have to manually make sure to resize the file either
ahead of time or when needed during writing.

Note that 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).

This fixes #262
@domenic
Copy link
Contributor

domenic commented Jan 23, 2021

extending a file with 0 bytes instead.

I found this very confusing, but after reading the spec change I understand you mean "some number of bytes whose value is 0", not "zero new bytes" :)

@mkruisselbrink
Copy link
Contributor Author

extending a file with 0 bytes instead.

I found this very confusing, but after reading the spec change I understand you mean "some number of bytes whose value is 0", not "zero new bytes" :)

Yeah, that was definitely written in a pretty confusing manner. Rephrased the description to be clearer.

@mkruisselbrink mkruisselbrink merged commit edc4d88 into main Feb 4, 2021
@mkruisselbrink mkruisselbrink deleted the seek-past-end-of-file branch February 4, 2021 22:01
github-actions bot added a commit that referenced this pull request Feb 4, 2021
Rather than rejecting when trying to write past the end of a file this
changes the spec to require extending a file with 0 bytes instead.

This enables creating sparse files (very useful for certain file formats
such as disk images). Additionally this greatly simplifies saving content
to a file when the data to be written is received out of order (such as in
the case of bittorrent downloads). Without this functionality such a
application would have to manually make sure to resize the file either
ahead of time or when needed during writing.

Note that 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).

This fixes #262

SHA: edc4d88
Reason: push, by @mkruisselbrink

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature-request seek past end of file
3 participants