common-streams
A collection of useful streams.
Install
npm install --save common-streams
Requires Node v6+
Usage
See ./test directory for more usage examples.
Example:
const rs = // e.g. fs.createReadStream(...)const ws = // e.g. fs.createWriteStream(...) const sha1Stream = 'sha1'const sizeStream = rsrsrs
HashStream
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
.
SizeStream
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.
RandomStream
new RandomStream(max)
Readable stream that emits max
random bytes before ending.
DiscardStream
new DiscardStream(start)
Swallows all bytes until start
is reached.
MeterStream
new MeterStream(max)
See meterstream