Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
into-stream
Advanced tools
The into-stream npm package allows you to convert various data types into readable streams. This is particularly useful when you need to work with streams but your data is not already in a stream format.
Convert String to Stream
This feature allows you to convert a string into a readable stream. The example code converts the string 'Hello, world!' into a stream and pipes it to the standard output.
const intoStream = require('into-stream');
const stream = intoStream('Hello, world!');
stream.pipe(process.stdout);
Convert Buffer to Stream
This feature allows you to convert a Buffer into a readable stream. The example code converts a Buffer containing 'Hello, world!' into a stream and pipes it to the standard output.
const intoStream = require('into-stream');
const buffer = Buffer.from('Hello, world!');
const stream = intoStream(buffer);
stream.pipe(process.stdout);
Convert Array to Stream
This feature allows you to convert an array into a readable stream. The example code converts an array of strings into a stream and logs each chunk to the console.
const intoStream = require('into-stream');
const array = ['Hello', 'world', '!'];
const stream = intoStream(array);
stream.on('data', chunk => console.log(chunk.toString()));
Convert Object to Stream
This feature allows you to convert an object into a readable stream. The example code converts an object into a stream and logs each chunk to the console.
const intoStream = require('into-stream');
const object = { key: 'value' };
const stream = intoStream.object(object);
stream.on('data', chunk => console.log(chunk));
The streamifier package also converts various data types into readable streams. It offers similar functionality to into-stream but with a slightly different API. For example, it provides methods like createReadStream for different data types.
The from2 package is another alternative that allows you to create readable streams from various data sources. It is more flexible in terms of stream creation and provides a more manual approach compared to into-stream.
The readable-stream package is a comprehensive implementation of Node.js streams. While it doesn't directly convert data types into streams, it provides the building blocks to create custom streams, offering more control and flexibility.
Convert a buffer/string/array/object into a stream
Correctly chunks up the input and handles backpressure.
$ npm install --save into-stream
const intoStream = require('into-stream');
intoStream('unicorn').pipe(process.stdout);
//=> 'unicorn'
Type: Buffer
string
Array<Buffer|string>
Returns: Readable stream
Adheres to the requested chunk size, except for array
where each element will be a chunk.
Type: object
, array<object>
Returns: Readable object stream
MIT © Sindre Sorhus
FAQs
Convert a string/promise/array/iterable/asynciterable/buffer/typedarray/arraybuffer/object into a stream
The npm package into-stream receives a total of 2,569,056 weekly downloads. As such, into-stream popularity was classified as popular.
We found that into-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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.