You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Forrest L Norvell c1afa53648 deps: upgrade npm to 2.11.0 10 years ago
..
node_modules deps: upgrade npm to 2.11.0 10 years ago
test deps: upgrade npm to 2.6.0 10 years ago
.npmignore npm: upgrade to v2.1.18 10 years ago
LICENSE deps: upgrade npm to 2.6.0 10 years ago
index.js deps: upgrade npm to 2.8.3 10 years ago
package.json deps: upgrade npm to 2.8.3 10 years ago
readme.md deps: upgrade npm to 2.8.3 10 years ago

readme.md

concat-stream

Writable stream that concatenates strings or binary data and calls a callback with the result. Not a transform stream -- more of a stream sink.

NPM

examples

Buffers

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
}

Arrays

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

Uint8Arrays

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('!!1'))

See test/ for more examples

methods

var 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 string
  • buffer - get back a Buffer
  • array - get an array of byte integers
  • uint8array, u8, uint8 - get back a Uint8Array
  • object, 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.

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.

license

MIT LICENSE