length-stream

length-stream - Simple pass-through stream (RW) which accumulates the length of the stream (streams2)

Usage no npm install needed!

<script type="module">
  import lengthStream from 'https://cdn.skypack.dev/length-stream';
</script>

README

length-stream

Simple pass-through stream (RW) which accumulates the length of the stream.

Build Status

Installation

npm install length-stream

Usage

If you provide a lengthListener when you construct the stream, it will be called with the resultant length of the stream just prior to end being emitted.

  • lengthStream(lengthListener) - constructs a new stream instance, lengthListener will be called prior to the end event being emitted
  • lengthListener function signature is fn(resultantLength)
var lengthStream = require('length-stream');
var resultLength;
function lengthListener(length) {
  resultLength = length;
}
var lstream = lengthStream(lengthListener); // create instance, lengthListener will get length
readstream
  .pipe(lstream) // length calculated as it passes through
  .pipe(...)

Goals

  • Easy to use pass-through stream which calculates the length of the string
  • Builds on pass-stream to have all the normal pass-through functionality for a spec compliant stream

Why

I find that when I am accumulating stream data, that I often need the resultant length, so rather than write the code over and over again to do that, this simple stream can be piped through and it will provide the resultant length when the stream ends by calling

Get involved

If you have input or ideas or would like to get involved, you may:

License