-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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] Add a fs.readAll
method to the fs
module (3/3)
#3422
Conversation
fs
modulefs
module (3/3)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## experimental/fs-readseek #3422 +/- ##
===========================================================
Coverage ? 73.14%
===========================================================
Files ? 263
Lines ? 20120
Branches ? 0
===========================================================
Hits ? 14717
Misses ? 4460
Partials ? 943
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
1b544ce
to
260307c
Compare
@codebien neither ReadableStream nor the associated ReadableStreamBYOBReader (including the broader I'm currently still unclear on how easy/intuitive it will be to consume a whole Stream once we implement that specification, and would need to do a bit of tinkering to figure it out. We had defined the I have no strong preference here. The alternatives to move forward at this point are:
Could you let me know what you prefer? |
At this point, considering all the uncertainty around Streams, let's add this helper function that improves the ergonomy for developers. We may drop or deprecate it in the future if a better alternative will appear. |
I don't see why at this point we will want to add ReadAll.
I am okay with reevaluating this at some future point when the module has been around for a while, has matured and there is a need for this. But at this point this seems to just add more code that we will need to maintain while we experiment with the module. |
fs
module (3/3)fs.readAll
method to the fs
module (3/3)
@mstoykov 👍🏻 My main goal with Closing this as a result 🙇🏻 |
What?
This Pull Request adds a
fs.readAll(file)
operation to the filesystem module. It follows a similar behavior to Deno's, and to Go'sio.ReadAll
, and allows users to retrieve the whole content of a file in a single function call.Just like with the
file.read
operation and the GoReader
, the operation moves the offset of the underlying file offset accordingly.Calling
readAll
from anoffset > 0
is supported and will read from the current offset until the end of the file.Calling
readAll
from the end of the file returnsnull
.Why?
This operation allows to reproduce the behavior of the current
open
function in thefs
module. It also acts as a convenience to read the whole content of a file, without having to resort to manual buffering +file.read
.It, however, differs a bit from the initial #3229 proposed design. We discussed it internally and reached the conclusion that the currently proposed design felt more idiomatic and convenient than having the operation on the
file
instance itself.Checklist
make lint
) and all checks pass.make tests
) and all tests pass.Related PR(s)/Issue(s)
ref #3229
ref #2974