A collection of useful streams.
npm install --save common-streams
Requires Node v6+
See ./test directory for more usage examples.
Example:
import { HashStream, SizeStream } from 'common-streams'
import concat from 'concat-stream'
const rs = getReadStream() // e.g. fs.createReadStream(...)
const ws = getWriteStream() // e.g. fs.createWriteStream(...)
const sha1Stream = new HashStream('sha1')
const sizeStream = new SizeStream()
rs.pipe(sha1Stream).pipe(concat(([{ digest }]) => {
console.log(digest, '=', '4129def2ea7cb7945ddfbb785969898fca2e34c3')
}))
rs.pipe(sizeStream).pipe(concat(([{ size }]) => {
console.log(size, '=', 2447774)
}))
rs.pipe(ws)
Transform stream that operates in object mode and returns a single { digest: 'hash digest' }
object.
new HashStream(algorithm, [, opts])
algorithm: any algorithm supported by crypto.createHash
opts.encoding: any encoding supported by hash.digest. Defaults to hex
.
Transform stream that operates in object mode and returns a single { size: 1000 }
object where the size is an integer representing the total
size in bytes of the stream.
new SizeStream()
If passed a callback new SizeStream(cb)
it will just act as a
PassThrough stream and call the callback when it's done.
new RandomStream(max)
Readable stream that emits max
random bytes before ending.
new DiscardStream(start)
Swallows all bytes until start
is reached.
new MeterStream(max)
See meterstream