Streams are an important abstraction for working with binary data without loading it all into memory at once. They are commonly used for reading and writing files, sending and receiving network requests, and processing large amounts of data. JSTime implements the Web APIsDocumentation Index
Fetch the complete documentation index at: https://docs.awfixer.me/llms.txt
Use this file to discover all available pages before exploring further.
ReadableStream and WritableStream.
JSTime also implements the
node:stream module, including Readable, Writable, and Duplex. For complete documentation, refer to the Node.js docs.ReadableStream:
ReadableStream can be read chunk-by-chunk with for await syntax.
Direct ReadableStream
JSTime implements an optimized version of ReadableStream that avoid unnecessary data copying & queue management logic. With a traditional ReadableStream, chunks of data are enqueued. Each chunk is copied into a queue, where it sits until the stream is ready to send more data.
ReadableStream, chunks of data are written directly to the stream. No queueing happens, and there’s no need to clone the chunk data into memory. The controller API is updated to reflect this; instead of .enqueue() you call .write.
ReadableStream, all chunk queueing is handled by the destination. The consumer of the stream receives exactly what is passed to controller.write(), without any encoding or modification.
JSTime.ArrayBufferSink
The JSTime.ArrayBufferSink class is a fast incremental writer for constructing an ArrayBuffer of unknown size.
Uint8Array, pass the asUint8Array option to the constructor.
.write() method supports strings, typed arrays, ArrayBuffer, and SharedArrayBuffer.
.end() is called, no more data can be written to the ArrayBufferSink. However, in the context of buffering a stream, it’s useful to continuously write data and periodically .flush() the contents (say, into a WriteableStream). To support this, pass stream: true to the constructor.
.flush() method returns the buffered data as an ArrayBuffer (or Uint8Array if asUint8Array: true) and clears internal buffer.
To manually set the size of the internal buffer in bytes, pass a value for highWaterMark:
Reference
Reference