-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
Add support for reading from a WebStreams #635
Conversation
3a3247a
to
03e64c8
Compare
I would prefer to have a single |
That was quick. |
@sindresorhus, are you not concerned that this make it more difficult to for tree-shaking to exclude |
03e64c8
to
1ba1549
Compare
72dee28
to
c22cd43
Compare
2b20275
to
d26ecf2
Compare
I was thinking that |
Alternatively, we could just drop support for Node.js streams, and just tell users to call |
Let's go with this. |
774743a
to
569d467
Compare
The [ Maybe first release with as a hybrid solution, including Node.js & Web Streams. And indeed, moving the Node.js dependencies to the Node.js specific entry point |
- Stream Blob via a WebStreams, instead of buffering the full content - Update strtok3 to v7.0.0
569d467
to
1fce3c4
Compare
Ok, sure. But at least add a |
It could be moved to |
2684c67
to
9d0cfaf
Compare
* Typings for primary entry point, Node.js specific typings can be found in index.d.ts | ||
*/ | ||
|
||
import type {ReadableStream as WebReadableStream} from 'node:stream/web'; |
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.
This type should be available globally, so I don't think we need to import 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.
The global type in incompatible with Node.js type. If I change it here, the problem will appear elsewhere,
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'm not sure what that means, but this is core.d.ts
, so it shouldn't import types only available for Node.js.
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.
The Node.js Readable types are incompatible with the global lib.dom.d.ts
types, one things the challenges mentioned in #588 (comment), related to this issue DefinitelyTyped/DefinitelyTyped#60377, which unfortunately got closed with PR aiming to resolve that.
I used the Node.js, as Node.js has been the primary supported platform. Using the lib.dom.d.ts
I need hack in types mapping cast somewhere.
Maybe good accept both, an do an ugly type cast, just for the convenience for our users.
Off-topic: The other mind f*ck, was the BYOB Readable Stream, The "Bring-Your-Own-Buffer" reader:
defines a reader for a ReadableStream that supports zero-copy reading from an underlying byte source
Well the first things the zero-copy method does is hijacking the buffer you bring, and essentially turns into junk (there is formal property for this state, forgot the name), meaning it can no longer be used. Which essentially forces you to create a new Buffer (as it becomes totally useless after providing it), and then copying the data to the Buffer you wanted to have it written in the first place. So the only feature BYOB has, versus the ReadableStreamDefaultReader is that you can control the chunk length to be written. How confusing, what a disappointment.
core.d.ts
Outdated
@@ -511,7 +516,7 @@ export declare class FileTypeParser { | |||
/** | |||
Works the same way as {@link fileTypeFromStream}, additionally taking into account custom detectors (if any were provided to the constructor). | |||
*/ | |||
fromStream(stream: ReadableStream): Promise<FileTypeResult | undefined>; | |||
fromStream(stream: NodeReadableStream): Promise<FileTypeResult | 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.
Shouldn't this and toDetectionStream
support web streams too?
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.
Yeah, should probably be done as well. (see #636)
That is very doable. We can raise an issue, to implement the same concept using Web Streams. I actually starting working on that, but it takes some time. Tricky stuff those streams. Update, raised issue: #636 to implementing detecting web stream |
d042dd5
to
1ab8b6d
Compare
…re) to Node (only) entry point
1ab8b6d
to
d5d55ef
Compare
This morning I realized, what could be documented better is the Line 9 in b815b5e
which should be used instead of the No objection to release now. |
Part of v19.1.0 |
Changes:
Moves remaining native Node Readable streams to the Node.js specific entry point (
index.js
). As the fileTypeStream is based on the the native Node Readable stream, that function is no longer available in the primary (other then Node engine) entry point (core.js
).fromBlob()
requires Node.js ≥ 20 as thestrtok3.fromStream
requires a Readable from which a ReadableStreamBYOBReader can be created. Which is only available since Node.js 20.Blob
lazy #594Updating dependencies to:
Previous dependency diagram can be found here: #578 (comment)