A stream meter that both counts the bytes piped through it, and can optionally abort on a max size. (e.g. limit a http request size)
Stream Meter is a... uh, meter for streams.
It is a streams2 Transform stream that passes through content, but counts the number of bytes it forwards.
However, give it a size in bytes and it will abort as soon as that threshold is passed. This is useful for capping your hyperquest or http/https clients or servers content size.
npm install stream-meter
var meter =// make an un-capped metervar m =processstdin// this will abort (with an Error) in the frame where 1024 bytes is reachedprocessstdin// create a 1024 byte-capped metervar m =mprocessstdin
var hyperquest =var req =var meter = 1024meterreq
$ node hypermeter.js 2> /dev/nullStream exceeded specified max of 1024 bytes.Read 7377 bytes
var meter =var stream =stream// read the bytes processed by the meter and passed through to any subsequent streams.var size = streambytes
See test/index.js for additional examples.
Size (in bytes) to trigger the stream to abort. It will complete whatever frame it aborted in, so the size streamed will still be >= size but no more than size + highWaterMark
Number of bytes handled and passed through the meter.