
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
split-to-streams
Advanced tools
A Node.JS stream.Transform interface that splits input into streams.
Given input, the StreamSplit class will split input in real-time, and provide a stream.Readable object for each segment delimited by delimiter.
Each stream.Readable provided, will in turn provide one or more data chunks, within the matched segment.
The utility of StreamSplit is to provide consumer interfaces the ability to process incoming chunks as they become available, without having to wait for a delimiter to be matched first.
_________________________________
| chunk | chunk | chunk | chunk | => { [chunk, chunk, chunk, chunk].join() }
----------- delimiter -----------
| chunk | chunk | chunk | chunk | => { [chunk, chunk, chunk, chunk].join() }
----------- delimiter -----------
_________________________________
| chunk | chunk | chunk | chunk | => { [Readable Stream] } => [ {chunk} | {chunk} | {chunk} | {chunk} ]
----------- delimiter -----------
| chunk | chunk | chunk | chunk | => { [Readable Stream] } => [ {chunk} | {chunk} | {chunk} | {chunk} ]
----------- delimiter -----------
delimiternpm install split-to-streams
npm test or node test/
const StreamSplit = require('split-to-streams');
const input = getReadableStream();
const spliter = new StreamSplit('\n'); // Split by LF
splitter.on('data', function (stream) {
// `stream` is a `stream.Readable` instance that will push data chunks within each line.
stream.on('data', function (chunk) {
// Handle chunks in a line.
});
});
input.pipe(splitter);
class StreamSplitThe class extends on stream.Transform and transforms input by splitting it based on a delimiter parameter.
constructor(delimiter = '' [, options = {}])Creates a new StreamSplit instance.
delimiter, the delimiter to split input byoptions (optional) Object with options to pass to the stream.Transform super.
ignorePrevious - default: false If set to true, disables partial matching.
createStream - (optional) - A custom function to create a stream.Readable-like object, every time the delimiter is matched.
This behavior has been corrected in v1.1.0
The first stream object will not be emitted at creation anymore, but on first write.
Overwriting createStream() method, before the first write, will not yield different objects anymore.
StreamSplitinstances will always emit a new stream object on creation, in order to capture initial chunks until and if first delimiter is found.As such, overwriting the
createStream()method after creation, will result in different objects being emitted (first will always be the default). Please useoptions.createStreamor by extending theStreamSplitclass, instead of replacing thecreateStream()method.
const StreamSplit = require('split-to-streams');
class MyCustomStreamSplit extends StreamSplit {
constructor( ... ) {
super( ... );
}
createStream() {
// Overwrite creating `stream.Readable` instances, and create custom objects.
// Note: object must have a `push()` method.
return new CustomObject();
}
_transform(chunk, encoding, callback) {
// Do something before passing the chunk to `StreamSplit`
super._transform(chunk, encoding, callback);
}
}
class SimpleSplitThe class extends on StreamSplit, but does not provide stream.Readable objects. Instead consumers can read chunks delimited by delimiter, just like with traditional string splitters.
constructor(delimiter = '' [, options = {}])Creates a new SimpleSplit instance.
delimiter, the delimiter to split input byoptions (optional) Object with options to pass to the stream.Transform super.class LineSplitThe class extends on SimpleSplit, and splits input by \n (LF) delimiters, providing lines as chunks.
const {LineSplit} = require('split-to-stream');
const lineSplitter = new LineSplit();
const input = getReadableStream(); // e.g. fs.createReadStream(filename);
lineSplitter.on('data', function(lineChunk) {
// handle lineChunk.
});
input.pipe(lineSplitter);
options.ignorePrevious to false, in contructor, to disable.delimiter.length greater than 1.Partial matching allows the StreamSplit class to quickly check incoming chunks for delimiter parts.
Sometimes, a delimiter matchs comes in via two or more separate chunks.
Example:
Full string: "Hello <delimiter>World"
Incoming chunks: ["Hello <del", "imit", "er>World"]
Partial matching, will inspect the end of each chunk, and if it finds a partial match of the delimiter, it will store that part. Differently from traditional splitters, it will release the unused part of the chunk, only keeping the partial match.
Flow example:
chunk "Hello <del":
- save( Buffer.from("<del") ); // partial match
- push( Buffer.from("Hello ") ); // send chunk to consumer streams.
chunk "imit":
- save( Buffer.from("imit") ); // partial match. entire stored buffer now "<delimit"
chunk "er>World":
- save( Buffer.from("er>") ); // partial match. entire stored buffer now "<delimiter>"
- emitDelimiterMatch(); // A delimiter matched
- push( Buffer.from("World") ); // send chunk to consumer streams.
Note: At the end of the input stream (input stream emits end), StreamSplit will push any remaining stored chunk, to the consumers; as expected in such scenarios.
MIT
FAQs
A Node.JS Transform interface that splits input into streams
We found that split-to-streams demonstrated a not healthy version release cadence and project activity because the last version was released 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.