What is into-stream?
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.
What are into-stream's main functionalities?
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));
Other packages similar to into-stream
streamifier
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.
from2
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.
readable-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.
into-stream
Convert a string/promise/array/iterable/buffer/typedarray/arraybuffer/object into a stream
Correctly chunks up the input and handles backpressure.
Install
$ npm install into-stream
Usage
const intoStream = require('into-stream');
intoStream('unicorn').pipe(process.stdout);
API
intoStream(input)
Type: Buffer
TypedArray
ArrayBuffer
string
Iterable<Buffer|string>
Promise
Returns: Readable stream
Adheres to the requested chunk size, except for array
where each element will be a chunk.
intoStream.object(input)
Type: Object
, Iterable<Object>
Promise
Returns: Readable object stream
Related
License
MIT © Sindre Sorhus