ion-js icon indicating copy to clipboard operation
ion-js copied to clipboard

Support for node streams?

Open everett1992 opened this issue 4 years ago • 5 comments

Does this library support, or plan to support, node's stream module? The makeReader function only accepts buffers. That requires reading the whole ion document into memory before beginning to parse.

everett1992 avatar Feb 10 '21 18:02 everett1992

ion-js needs to support both node and browser runtimes. Is there a common stream API we could code against for both?

zslayton avatar Feb 10 '21 18:02 zslayton

Looking at the library I don't think it would be easy to target node's stream api because it is async and callback based, while next and stepin are sync.

I see an experimental web streams api, but it's not the same as nodes. https://developer.mozilla.org/en-US/docs/Web/API/Streams_API

I'm going to try reading the stream in a worker_thread, pushing data into a SharedArrayBuffer, and using Atomics.wait to block the main thread.

everett1992 avatar Feb 10 '21 19:02 everett1992

After some initial success I've hit a roadblock https://stackoverflow.com/questions/66145735/is-there-a-blocking-arraybuffer-that-is-filled-by-a-worker-thread

everett1992 avatar Feb 10 '21 22:02 everett1992

i would say iterators are the common factor, and it's easy to create a node stream from it

stream.Readable.from(iterator)

think there was some proposal also about ReadableStream.from(iterable) too (for web)

jimmywarting avatar Oct 22 '22 01:10 jimmywarting

@jimmywarting Can you please elaborate maybe with an example of using an iterator for reader API? Did you mean to provide an iterator for DOM values (It does mean materializing Ion data to DOM values)?

desaikd avatar Oct 25 '22 21:10 desaikd