UNPKG

tar

Version:
18 lines • 568 B
/** * Make a stream of the chunks of an iterator. It asks the iterator * for a chunk only when a consumer reads the stream. A cancel of the * stream calls `return()` of the iterator. */ export const toStream = (chunks) => new ReadableStream({ pull: async (controller) => { const res = await chunks.next(); if (res.done) controller.close(); else controller.enqueue(res.value); }, cancel: async () => { await chunks.return?.(); }, }, { highWaterMark: 0 }); //# sourceMappingURL=to-stream.js.map