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

feat: implement createReadStream and createWriteStream on FileHandle #1076

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

graue
Copy link
Contributor

@graue graue commented Nov 27, 2024

Closes #1063

Thanks for making this library! My test needed these methods to exist so I took a stab at adding support.

@graue
Copy link
Contributor Author

graue commented Nov 28, 2024

Well, that's embarrassing: the first version of this that I submitted didn't work, due to another issue: the fs.createWriteStream method as defined on memfs volumes did not allow the fd option to be a FileHandle, as Node.js's fs module does.

In my second commit, I've aligned that behavior with the Node API (which makes my first commit work), and in my third commit, I've added a test for this. Let me know if you want me to rebase, or handle any of this differently.

@G-Rath G-Rath changed the title Implement create{Read,Write}Stream on FileHandle feat: implement createReadStream and createWriteStream on FileHandle Nov 28, 2024
@G-Rath
Copy link
Collaborator

G-Rath commented Nov 28, 2024

the fs.createWriteStream method as defined on memfs volumes did not allow the fd option to be a FileHandle

would you be ok doing a dedicated PR for that? it sounds like it's a clean bugfix that can get its own version and changelog entry

@graue
Copy link
Contributor Author

graue commented Nov 28, 2024

Done: #1077

I'll wait for that to be merged then rebase this.

@graue graue force-pushed the fh-createwritestream branch from 21f729d to c550f22 Compare December 2, 2024 02:15
@graue
Copy link
Contributor Author

graue commented Dec 2, 2024

Rebased!

@@ -33,6 +33,14 @@ export class FileHandle implements IFileHandle {
return promisify(this.fs, 'fdatasync')(this.fd);
}

createReadStream(options: opts.IFileHandleReadStreamOptions): IReadStream {
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it be possible to get some basic tests for these?

Copy link
Contributor Author

@graue graue Dec 4, 2024

Choose a reason for hiding this comment

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

Done (adapted from the equivalent tests for the volume interface)

@graue
Copy link
Contributor Author

graue commented Dec 9, 2024

@G-Rath, I think this is ready to go! The X is only because it doesn't like my commit message for the second commit; squashing will fix that. Would be nice to get this in so I can use an official release in my project :)

@G-Rath G-Rath merged commit c413df5 into streamich:master Dec 9, 2024
9 of 10 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 9, 2024
# [4.15.0](v4.14.1...v4.15.0) (2024-12-09)

### Features

* implement `createReadStream` and `createWriteStream` on `FileHandle` ([#1076](#1076)) ([c413df5](c413df5)), closes [#1063](#1063)
Copy link

github-actions bot commented Dec 9, 2024

🎉 This PR is included in version 4.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@graue graue deleted the fh-createwritestream branch December 9, 2024 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

memfs.createWriteStream() exists, while filehandle.createWriteStream() doesn't
2 participants