GitXplorerGitXplorer
b

node-stream-meter

public
29 stars
4 forks
1 issues

Commits

List of commits on branch master.
Unverified
c4ac12861e3097c3d59d2043d94077f2728a837a

1.0.4

bbrycebaril committed 9 years ago
Unverified
4054e12be7eb6b8d8a8fac1bb2c53199c467674b

Merge branch 'trenskow-master'

bbrycebaril committed 9 years ago
Unverified
bcbcd49f73483271ecaf597a79c991a1a8746ea9

Updated outdated packages.

ttrenskow committed 9 years ago
Unverified
5c768032bd15238a0d5a8afc868507ac78897850

update deps

bbrycebaril committed 11 years ago
Unverified
654f4131d52b49537fcc96bebb4d8726c8e64f9a

1.0.3

bbrycebaril committed 11 years ago
Unverified
6d4596929d17a23e18846ff3334eda50d8800a5f

Swap tap for tape, add badges to README.

bbrycebaril committed 11 years ago

README

The README file for this repository.

Stream Meter

NPM

david-dm david-dm

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

Examples:

var meter = require("stream-meter")

// make an un-capped meter
var m = meter()
process.stdin.pipe(m).pipe(process.stdout)
setTimeout(function () {
  // Log how much we saw in a couple seconds.
  console.log(m.bytes)
}, 2000)

// this will abort (with an Error) in the frame where 1024 bytes is reached
process.stdin.pipe(meter(1024)).pipe(process.stdout)

// create a 1024 byte-capped meter
var m = meter(1024)
m.on("error", function (e) {
  // log the error but don't kill the process
  console.log(e.message)
})
process.stdin.pipe(m).pipe(process.stdout)
var hyperquest = require("hyperquest")

var req = hyperquest("https://raw.github.com/mranney/node_redis/master/index.js")

var meter = require("stream-meter")(1024)
meter.on("error", function (e) {
  console.log(e.message)
  console.log("Read %s bytes", meter.bytes)
})


req.pipe(meter).pipe(process.stderr)
$ node hypermeter.js 2> /dev/null
Stream exceeded specified max of 1024 bytes.
Read 7377 bytes

Usage

var meter = require("stream-meter")

var stream = meter(size)
stream.on("error", function (e) {
  // handle the meter aborting the stream
})

// read the bytes processed by the meter and passed through to any subsequent streams.
var size = stream.bytes

See test/index.js for additional examples.

Options

size

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

Properties

bytes

Number of bytes handled and passed through the meter.

LICENSE

MIT