concat-stream
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
inherits | 2.0.4 | 1.98 kB | ISC | prod | |
readable-stream | 1.1.14 | 20.15 kB | MIT | prod | |
typedarray | 0.0.7 | 10.21 kB | MIT | prod |
Concat-Stream is a writable stream utility that concatenates all data from a stream and calls a callback with the compiled result. It proves especially useful when you need to collect all data from a stream into a single buffer. It's suitable for situations where you can accommodate the stream's entire output in a single Buffer, like within RAM. Notably, it also supports objectMode streams emitting objects other than Buffers.
Utilizing Concat-Stream requires you first to install the package into your project. You can accomplish this by running npm install concat-stream
in your project directory.
Once installed, you can use Concat-Stream as shown in the examples below:
var fs = require('fs')
var concat = require('concat-stream')
var readStream = fs.createReadStream('cat.png')
var concatStream = concat(gotPicture)
readStream.on('error', handleError)
readStream.pipe(concatStream)
function gotPicture(imageBuffer) {
// imageBuffer is all of `cat.png` as a node.js Buffer
}
function handleError(err) {
// handle your error appropriately here, e.g.:
console.error(err) // print the error to STDERR
process.exit(1) // exit program with non-zero exit code
}
var write = concat(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
var write = concat(function(data) {})
var a = new Uint8Array(3)
a[0] = 97; a[1] = 98; a[2] = 99
write.write(a)
write.write('!')
write.end(Buffer.from('!!1'))
The Concat-Stream documentation can be found on the project's GitHub page at https://github.com/maxogden/concat-stream. In addition to the package's description and usage examples, the documentation provides information on error handling, licensing, and related stream utilities under the mississippi stream utility collection. Simply navigate to the provided URL to peruse the full documentation.