{"_id":"writable-consumable-stream@5.0.1","bugs":{"url":"https://github.com/SocketCluster/writable-consumable-stream/issues"},"dist":{"shasum":"792a6700519f5202a12a4e25cfff62a0bb30d29b","tarball":"http://registry-npm.ywwl.com/writable-consumable-stream/download/writable-consumable-stream-5.0.1.tgz","fileCount":9,"integrity":"sha512-LgpAGXItl5s0fl7q/cIfvZ5QrqJyKj7KP0w1Fa+lI5o8sxSCLOR4Y1I/AWGYGpz3b3TzUU7yGiqke0Tti7Gf4w==","signatures":[{"sig":"MEQCIDe/dWn0zzK4Ovg2Fo3+xUXBq5FBUUCPOX4uShRb4sLSAiAmkrLvDmP/fAQIRp554tnASB7wpcwSNDNhpzKDb9QAZg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCncnP/xKKl4qs9a3F67N6AwEZ2Oo35LIHG5uxodnwcpwIgdxCR9WfzavcE81DYtRk0zVwKIe5vmWUUmOlyQ//NoRU="}],"unpackedSize":89090,"size":13692,"noattachment":false,"key":"/writable-consumable-stream/-/writable-consumable-stream-5.0.1.tgz"},"main":"index.js","name":"writable-consumable-stream","author":{"name":"Jonathan Gros-Dubois"},"gitHead":"a32f0a028f651b8308edee1a64c8b010e242f80a","license":"MIT","scripts":{"test":"./node_modules/mocha/bin/_mocha --reporter spec --timeout 10000 --slow 10000","build":"rollup --config ./rollup.config.js"},"version":"5.0.1","_npmUser":{"name":"topcloudsystems","email":"grosjona@yahoo.com.au"},"homepage":"https://github.com/SocketCluster/writable-consumable-stream#readme","keywords":["async","generator","stream","data","for-await-of"],"repository":{"url":"git+ssh://git@github.com/SocketCluster/writable-consumable-stream.git","type":"git"},"_npmVersion":"11.6.2","description":"An async stream which can be iterated over using a for-await-of loop.","directories":{},"maintainers":[{"name":"topcloudsystems","email":"grosjona@yahoo.com.au"}],"_nodeVersion":"24.11.1","dependencies":{"consumable-stream":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^10.2.0","rollup":"^3.28.1","@rollup/plugin-terser":"^0.4.3","@rollup/plugin-commonjs":"^25.0.4","@rollup/plugin-node-resolve":"^15.2.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/writable-consumable-stream_5.0.1_1791522245382_0.35750000711700514"},"readme":"# writable-consumable-stream\nAn async stream which can be iterated over using a for-await-of loop and which can be written to.\n\nThe `WritableConsumableStream` class extends the `ConsumableStream` class.  \nSee https://github.com/SocketCluster/consumable-stream\n\n## Installation\n\n```\nnpm install writable-consumable-stream\n```\n\n## Usage\n\n### Require\n\n```js\nconst WritableConsumableStream = require('writable-consumable-stream');\n```\n\n### Consume a stream and write to it asynchronously:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\nasync function consumeAsyncIterable(asyncIterable) {\n  // Consume iterable data asynchronously.\n  for await (let packet of asyncIterable) {\n    console.log('Packet:', packet);\n  }\n}\nconsumeAsyncIterable(consumableStream);\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Consume a stream using a while loop:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\nasync function consumeAsyncIterable(asyncIterable) {\n  // Consume iterable data asynchronously.\n  // Works in older environments.\n  let asyncIterator = asyncIterable.createConsumer();\n  while (true) {\n    let packet = await asyncIterator.next();\n    if (packet.done) break;\n    console.log('Packet:', packet.value);\n  }\n}\nconsumeAsyncIterable(consumableStream);\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Consume a filtered stream using an async generator:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\n// Creates an async generator which only produces packets which are allowed by the\n// specified filterFunction.\nasync function* createFilteredStreamGenerator(fullStream, filterFunction) {\n  for await (let packet of fullStream) {\n    if (filterFunction(packet)) {\n      yield packet;\n    }\n  }\n}\n\nasync function consumeAsyncIterable(asyncIterable) {\n  // Consume iterable data asynchronously.\n  for await (let packet of asyncIterable) {\n    console.log('Packet:', packet);\n  }\n}\n\n// The filter function will only include strings which end with the number 5.\nfunction filterFn(data) {\n  return /5$/.test(data);\n}\nlet filteredStreamGenerator = createFilteredStreamGenerator(consumableStream, filterFn);\n\nconsumeAsyncIterable(filteredStreamGenerator);\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Consume only the next data object which will be written to the stream:\n\n```js\nlet consumableStream = new WritableConsumableStream();\n\n(async () => {\n  let data = await consumableStream.once();\n  console.log(data);\n})();\n\nsetInterval(() => {\n  // Write data to the stream asynchronously,\n  consumableStream.write(`Timestamp: ${Date.now()}`);\n}, 100);\n```\n\n### Releasing a consumer\n\nKilling or closing a consumer removes it from the stream but does not discard the\npackets which it has not consumed yet - this is what allows a consumer to resume\nlater without missing any messages. For as long as a consumer is still reachable,\nthose packets, and everything written to the stream afterwards, stay in memory.\n\nSo once you are finished with a consumer, `break` out of its `for await...of` loop,\nor kill it with `stream.killConsumer(consumer.id)` (or `stream.kill()` for all\nconsumers) and discard any remaining references to it.\n\nSee `test/` directory for additional examples.\n","publish_time":1791522245509,"_cnpm_publish_time":1791522245509,"dist-tags":{"latest":"5.0.1"}}