1.0.0 • Published 10 years ago

size-limit-stream v1.0.0

Weekly downloads
160
License
BSD
Repository
github
Last release
10 years ago

size-limit-stream

NPM

js-standard-style

Build Status

a through stream that destroys itself if an overall size limit for the combined stream throughput is exceeded. useful for e.g. limiting HTTP upload size

usage

limitStream(limit)

returns a through stream

example:

var limiter = limitStream(1024 * 5) // 5kb max

example

create a stream that concatenates input, but only if input is less than the limit:

var pumpify = require('pumpify')
var concat = require('concat-stream')
var limitStream = require('size-limit-stream')

function uploadStream (cb) {
  var limiter = limitStream(1024 * 5) // 5kb max
  var concatter = concat(function concatted (buff) {
    cb(null, buff)
  })

  var combined = pumpify(limiter, concatter)
  combined.on('error', cb)
  
  return combined
}