Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fs: fix
fs.openAsBlob
, addfs.openAsBlobSync
andfsPromises.openAsBlob
#49759base: main
Are you sure you want to change the base?
fs: fix
fs.openAsBlob
, addfs.openAsBlobSync
andfsPromises.openAsBlob
#49759Changes from all commits
1174c94
a48718b
fe64e58
0b246e4
5e87bbb
319061b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Help me understand - why do we actually need an async API with a callback for this if it's always called synchronously?
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.
Just to have it aligned on API level. Having a function that pretends (at least, for now) to be async is less weird that not having it in other APIs at all.
I would like to see this PR superseded or followed up with proper implementation and maybe switch from
Blob
toFile
, but judging from #45258 (comment) the former seems to be problematic.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 miss @addaleax 😍 , I think she was spot on and the impl shouldn't use blocking I/O here and return a promise/take a callback that's quite confusing IMO.
Additionally I think in the case of Blob we can probably return immediately and defer access to the file to the point someone actually tries to do something with the blob. That can be synchronous and perform no I/O and would arguably be a better API (since it makes no assumptions about the file in-between creating the Blob and accessing it)
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 think it's highly likely that they will do something with the blob if they have called
openAsBlob
i think it should check if the file exist and throw a DOMexception NotFoundError otherwise.
it's not a case about if but when they will do any I/O operation after having called
openAsBlob
. Developers are most likely going to use it at some point. So why not just do it upfront right away rather then later? it's going to do all this work anywayIt should also guard against modifications afterwards.
I believe browser do also support renaming the file and moving it to another folder and still being readable afterwards. think i remember testing this a long time ago but can't remember if that was the case.
so i don't think the type, size, filename and lastModified date should be changeable after having called
openAsBlob
so that would involve having tostat
the file and look up some properties for it.I don't think it should be possible to call
openAsBlob(path)
on a path that dose not exist, create the file and then do ablob.text()
afterwards. that would just be weird and unexpected.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 kinda see the point of deferring the reading operations: the methods that allow reading content like
Blob.prototype.arrayBuffer
,Blob.prototype.text
are async, so we only need stats to be determined immediately.In case if I plan to read it via
Blob.prototype.stream
, I would be surprised to see that Node.js swallows whole file and keeps it in memory before even constructing the stream. After all, it's calledopenAsBlob
and notreadAsBlob
.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.
Yup! Blob/File are more like FileSystemFileHandle or fs.FileHandle that just points to somewhere where it can locate and read the data from. (and what start/end offset it has)
a blob don't read anything to memory (or at least it should not - unless it's constructed from memory)