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

Consider exposing intenal read method as separate export #52

Closed
Gozala opened this issue Jul 12, 2020 · 2 comments
Closed

Consider exposing intenal read method as separate export #52

Gozala opened this issue Jul 12, 2020 · 2 comments

Comments

@Gozala
Copy link
Contributor

Gozala commented Jul 12, 2020

In our code base we abstract between node & browser via function that reads contents as AsyncIterable<Uint8Array>. This library internally has read that pretty much does that, which then is wrapped in a node Readable.

Maybe instead of providing web incompatible stream() method internal read() could be exposed instead ?

@jimmywarting
Copy link
Contributor

jimmywarting commented Jul 23, 2020

Why don't you use native web blob instead?

I have recently been thinking how to make this Deno compatible...
two think need to happen then.

  1. have to change to es6 module so this can be imported into any Deno code using import statement.
  2. make node-stream a optional dependency
stream () {
  if (globalThis.ReadableStream?.from) {
    return ReadableStream.from(read(...))
  } else {
    import('stream').then(({Readable}) => Readable.from(read(...)))
  }
}

Deno and browser have whatwg - ReadableStream


would it help if this used whatwg streams instead of exposing read?

Edit: just saw that you mention something like it in #51

@Gozala
Copy link
Contributor Author

Gozala commented Jul 23, 2020

Why don't you use native web blob instead?

We do on the web, but share the same code with node. So we need a common reading function with little to no overhead.

I have recently been thinking how to make this Deno compatible...
two think need to happen then.

👍

  • have to change to es6 module so this can be imported into any Deno code using import statement.
  • make node-stream a optional dependency
stream () {
 if (globalThis.ReadableStream?.from) {
   return ReadableStream.from(read(...))
 } else {
   import('stream').then(({Readable}) => Readable.from(read(...)))
 }
}

Deno and browser have whatwg - ReadableStream

This is more or less what I end up doing in https://github.com/Gozala/web-blob. It does subclass ReadableStream to provide no overhead access to it as AsyncIterable:

https://github.com/Gozala/web-blob/blob/73a00234e9a8ea25a8b300ca6982ec2b843e3a43/src/lib.js#L203-L208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants