Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

size-limit-stream

1.0.0 • Public • Published

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
}

install

npm i size-limit-stream

Downloadsweekly downloads

213

version

1.0.0

license

BSD

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability