-
Notifications
You must be signed in to change notification settings - Fork 31
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
fix: avoid reading files when the size is empty #134
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
also made sure it checks the stat.size if it has changed for good measures... some application can change the content without modifying the date |
@@ -65,6 +65,9 @@ class BlobDataItem { | |||
this.#start = options.start | |||
this.size = options.size | |||
this.lastModified = options.lastModified | |||
this.originalSize = options.originalSize === undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally try to treat null and undefined the same in the code, to avoid unexpected behaviour. This also lets us transition to the ??
operator when we drop support for Node.js 12.x, without changing the behaviour of the code.
this.originalSize = options.originalSize === undefined | |
this.originalSize = options.originalSize == null |
(x == null
is the same as x === undefined || x === null
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know that, i also try to avoid null from time to times. and i can't wait until we can start using ??=
but i wanted to avoid using == instead of === and breaking any compatibility with nullish stuff
also since there is no occurrences of null in the code, then i tought it would be fine to just check for undefined
could also just do this.originalSize = options.originalSize || options.size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.originalSize || options.size
will use options.size
if options.originalSize
is 0
though, that's probably not what we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought about it too, but after commit 568b309 then that might not be needed after all, cuz 0-sized blob and typedarrays will not be in the source anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat 👍
The purpose of this PR is:
... to fix a range error when it tries to read a empty file:
"RangeError [ERR_OUT_OF_RANGE]: The value of "end" is out of range. It must be >= 0 && <= 9007199254740991. Received -1"
This is what had to change:
... Avoid pushing empty chunks into the bucket and avoid reading them all together.
This is what like reviewers to know:
... this affected the blob backed up by the filesystem
docs:
,fix(area):
,feat(area):
orbreaking(area):