Open benlesh opened 12 months ago
One thing I'll mention before addressing your feedback...
I personally found the initial example to be a bit hard to follow, where I was bouncing around inside the code to figure out what was being read, what happens when it's read, and what's initializing the read.
The getFile()
method is specified over in https://github.com/whatwg/fs (here). So
While I understand that
fetch
generally has fewer ways of getting http responses than something dealing with opening and reading files, this API -- with regards to reading files in particular -- is surprisingly divergent, IMO.
The prior art this API builds on is FileSystemFileEntry.file()
which returns (via a callback, since it predates promises) a File
. File
extends Blob
, from which you can (among other things) get a ReadableStream
(which is what response.body
gets you)
const readableStream = (await fileHandle.getFile()).stream()
While I understand that
fetch
generally has fewer ways of getting http responses than something dealing with opening and reading files, this API -- with regards to reading files in particular -- is surprisingly divergent, IMO. I personally found the initial example to be a bit hard to follow, where I was bouncing around inside the code to figure out what was being read, what happens when it's read, and what's initializing the read.I guess I would have expected something like
fetch
and how you read thebody
:Where a file read that aligns more with the existing API might look like: