
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
writable-consumable-stream
Advanced tools
An async stream which can be iterated over using a for-await-of loop.
An async stream which can be iterated over using a for-await-of loop and which can be written to.
The WritableConsumableStream
class extends the ConsumableStream
class.
See https://github.com/SocketCluster/consumable-stream
npm install writable-consumable-stream
const WritableConsumableStream = require('writable-consumable-stream');
let consumableStream = new WritableConsumableStream();
async function consumeAsyncIterable(asyncIterable) {
// Consume iterable data asynchronously.
for await (let packet of asyncIterable) {
console.log('Packet:', packet);
}
}
consumeAsyncIterable(consumableStream);
setInterval(() => {
// Write data to the stream asynchronously,
consumableStream.write(`Timestamp: ${Date.now()}`);
}, 100);
let consumableStream = new WritableConsumableStream();
async function consumeAsyncIterable(asyncIterable) {
// Consume iterable data asynchronously.
// Works in older environments.
let asyncIterator = asyncIterable.createConsumer();
while (true) {
let packet = await asyncIterator.next();
if (packet.done) break;
console.log('Packet:', packet.value);
}
}
consumeAsyncIterable(consumableStream);
setInterval(() => {
// Write data to the stream asynchronously,
consumableStream.write(`Timestamp: ${Date.now()}`);
}, 100);
let consumableStream = new WritableConsumableStream();
// Creates an async generator which only produces packets which are allowed by the
// specified filterFunction.
async function* createFilteredStreamGenerator(fullStream, filterFunction) {
for await (let packet of fullStream) {
if (filterFunction(packet)) {
yield packet;
}
}
}
async function consumeAsyncIterable(asyncIterable) {
// Consume iterable data asynchronously.
for await (let packet of asyncIterable) {
console.log('Packet:', packet);
}
}
// The filter function will only include strings which end with the number 5.
function filterFn(data) {
return /5$/.test(data);
}
let filteredStreamGenerator = createFilteredStreamGenerator(consumableStream, filterFn);
consumeAsyncIterable(filteredStreamGenerator);
setInterval(() => {
// Write data to the stream asynchronously,
consumableStream.write(`Timestamp: ${Date.now()}`);
}, 100);
let consumableStream = new WritableConsumableStream();
(async () => {
let data = await consumableStream.once();
console.log(data);
})();
setInterval(() => {
// Write data to the stream asynchronously,
consumableStream.write(`Timestamp: ${Date.now()}`);
}, 100);
See test/
directory for additional examples.
FAQs
An async stream which can be iterated over using a for-await-of loop.
We found that writable-consumable-stream demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.