Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
concat-stream
Advanced tools
writable stream that concatenates strings or binary data and calls a callback with the result
The concat-stream npm package is a writable stream that concatenates data and calls a callback with the result. It can be used to collect stream data and concatenate it into a single buffer, string, or array. It is useful for collecting stream data from sources like HTTP requests, file reads, and other stream sources.
Concatenate stream data into a buffer
This code sample demonstrates how to use concat-stream to read data from a file and concatenate it into a buffer. The buffer is then converted to a string and logged to the console.
const concat = require('concat-stream');
const fs = require('fs');
const readStream = fs.createReadStream('file.txt');
const concatStream = concat(function(buffer) {
console.log(buffer.toString());
});
readStream.pipe(concatStream);
Concatenate stream data into a string
This code sample shows how to use concat-stream to collect HTTP response data and concatenate it into a string. The string is then logged to the console.
const concat = require('concat-stream');
const http = require('http');
http.get('http://example.com', function(response) {
response.pipe(concat(function(data) {
console.log(data.toString());
}));
});
Concatenate stream data into an array
This example demonstrates how to use concat-stream to collect data from a readable stream and concatenate it into an array. The resulting array is then logged to the console.
const concat = require('concat-stream');
const { Readable } = require('stream');
const arrayStream = Readable.from(['hello', ' ', 'world']);
const concatStream = concat({ encoding: 'array' }, function(array) {
console.log(array);
});
arrayStream.pipe(concatStream);
The 'bl' (Buffer List) package is similar to concat-stream as it provides a storage object for collections of Node.js Buffers. It can be used to collect buffers and access them with a standard readable Buffer interface. It differs in its API and additional features like the ability to access data at specific indices without creating a new Buffer.
The 'stream-buffers' package offers writable and readable stream implementations using a growable buffer. It is similar to concat-stream in that it allows for the collection of stream data, but it also provides more control over the buffer size and growth.
Writable stream that concatenates strings or binary data and calls a callback with the result. Not a transform stream -- more of a stream sink.
var concat = require('concat-stream')
var fs = require('fs')
var read = fs.createReadStream('readme.md')
var write = concat(function(data) {})
read.pipe(write)
works with arrays too!
var write = concat({ encoding: 'array' }, function(data) {})
write.write([1,2,3])
write.write([4,5,6])
write.end()
// data will be [1,2,3,4,5,6] in the above callback
works with buffers too! can't believe the deals!
var write = concat(function(data) {})
write.write(new Buffer('hello '))
write.write(new Buffer('world'))
write.end()
// data will be a buffer that toString()s to 'hello world' in the above callback
or if you want a Uint8Array, you can have those too!
var write = concat({ encoding: 'u8' }, function(data) {})
var a = new Uint8Array(3)
a[0] = 97; a[1] = 98; a[2] = 99
write.write(a)
write.write('!')
write.end(Buffer('!!1'))
var concat = require('concat-stream')
Return a writable
stream that will fire cb(data)
with all of the data that
was written to the stream. Data can be written to writable
as strings,
Buffers, arrays of byte integers, and Uint8Arrays.
Use opts.encoding
to control what format data
should be:
MIT LICENSE
FAQs
writable stream that concatenates strings or binary data and calls a callback with the result
The npm package concat-stream receives a total of 18,070,848 weekly downloads. As such, concat-stream popularity was classified as popular.
We found that concat-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.