writable stream that concatenates strings or data and calls a callback with the result
Installations
npm install concat-stream
Releases
Unable to fetch releases
Developer
maxogden
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
10.13.0
NPM Version
6.4.1
Statistics
573 Stars
112 Commits
64 Forks
13 Watching
3 Branches
20 Contributors
Updated on 25 Sept 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
6,076,095,468
Last day
-7.6%
4,374,744
Compared to previous day
Last week
2%
26,214,509
Compared to previous week
Last month
17.4%
104,497,006
Compared to previous month
Last year
-2.2%
1,085,882,693
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Dev Dependencies
1
concat-stream
Writable stream that concatenates all the data from a stream and calls a callback with the result. Use this when you want to collect all the data from a stream into a single buffer.
description
Streams emit many buffers. If you want to collect all of the buffers, and when the stream ends concatenate all of the buffers together and receive a single buffer then this is the module for you.
Only use this if you know you can fit all of the output of your stream into a single Buffer (e.g. in RAM).
There are also objectMode
streams that emit things other than Buffers, and you can concatenate these too. See below for details.
Related
concat-stream
is part of the mississippi stream utility collection which includes more useful stream modules similar to this one.
examples
Buffers
1var fs = require('fs') 2var concat = require('concat-stream') 3 4var readStream = fs.createReadStream('cat.png') 5var concatStream = concat(gotPicture) 6 7readStream.on('error', handleError) 8readStream.pipe(concatStream) 9 10function gotPicture(imageBuffer) { 11 // imageBuffer is all of `cat.png` as a node.js Buffer 12} 13 14function handleError(err) { 15 // handle your error appropriately here, e.g.: 16 console.error(err) // print the error to STDERR 17 process.exit(1) // exit program with non-zero exit code 18} 19
Arrays
1var write = concat(function(data) {}) 2write.write([1,2,3]) 3write.write([4,5,6]) 4write.end() 5// data will be [1,2,3,4,5,6] in the above callback
Uint8Arrays
1var write = concat(function(data) {}) 2var a = new Uint8Array(3) 3a[0] = 97; a[1] = 98; a[2] = 99 4write.write(a) 5write.write('!') 6write.end(Buffer.from('!!1'))
See test/
for more examples
methods
1var concat = require('concat-stream')
var writable = concat(opts={}, cb)
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.
By default concat-stream
will give you back the same data type as the type of the first buffer written to the stream. Use opts.encoding
to set what format data
should be returned as, e.g. if you if you don't want to rely on the built-in type checking or for some other reason.
string
- get a stringbuffer
- get back a Bufferarray
- get an array of byte integersuint8array
,u8
,uint8
- get back a Uint8Arrayobject
, get back an array of Objects
If you don't specify an encoding, and the types can't be inferred (e.g. you write things that aren't in the list above), it will try to convert concat them into a Buffer
.
If nothing is written to writable
then data
will be an empty array []
.
error handling
concat-stream
does not handle errors for you, so you must handle errors on whatever streams you pipe into concat-stream
. This is a general rule when programming with node.js streams: always handle errors on each and every stream. Since concat-stream
is not itself a stream it does not emit errors.
We recommend using end-of-stream
or pump
for writing error tolerant stream code.
license
MIT LICENSE
Stable Version
The latest stable version of the package.
Stable Version
2.0.0
MODERATE
3
0/10
Summary
Memory Exposure in concat-stream
Affected Versions
>= 1.3.0, < 1.3.2
Patched Versions
1.3.2
0/10
Summary
Memory Exposure in concat-stream
Affected Versions
>= 1.4.0, < 1.4.11
Patched Versions
1.4.11
0/10
Summary
Memory Exposure in concat-stream
Affected Versions
>= 1.5.0, < 1.5.2
Patched Versions
1.5.2
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 8/27 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Score
3.3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More