UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

26 lines 769 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cacheStream = void 0; const CachableStream_1 = require("@johngw/stream/sources/CachableStream"); /** * Wraps a `ReadableStream` in a `CachableStream`. * * @group Sources * @example * ``` * const controller = new ControllableStream<number>() * * cacheStream( * new StorageCache(new MemoryCache(), 'my-cache', 30 * 60_000)), * ['a', 'cache', 'path'] * controller, * ) * .pipeTo(write(console.info)) * ``` */ function cacheStream(cache, path, stream, ms) { const reader = stream.getReader(); return new CachableStream_1.CachableStream(cache, path, async () => reader.read(), ms); } exports.cacheStream = cacheStream; //# sourceMappingURL=cacheStream.js.map