String to Stream
Convert string into a readable stream.
Installation
$ npm install str-to-stream
Usage
Pipe a string into a writable stream:
const strToStream = ; const stream = ; stream;
Listen to data
event:
const strToStream = ; const stream = ; stream; stream;
Recipes
Set the Data Bytes Limit for Each Chunk
By default, each data chunk is limited to 16,384 bytes. You can override this by passing the highWaterMark
option:
const strToStream = ; const stream = ; const chunks = ; stream; stream; // ["hello ", "world!"]
Emit Data in One Shot
To emit all string data in one shot, set the objectMode
option to true
. The highWaterMark
option value won't have any effect.
const strToStream = ; const stream = ; stream;
Write to a File
const fs = ;const strToStream = ; const file = fs; const stream = ; stream;
API
Parameters
data
(String
): The string to convert to a readable stream.highWaterMark
(optionalNumber
): The maximum number of bytes for each chunk, default to16384
(16kb).objectMode
(optionalBoolean
): When it sets totrue
, the stringdata
will be emitted in one shot ignoring thehighWaterMark
option. Default tofalse
.
Returns
It returns Readable
Stream instance.