Socket
Socket
Sign inDemoInstall

through

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

through - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

test/buffering.js

45

index.js

@@ -8,2 +8,4 @@ var Stream = require('stream')

exports = module.exports = through

@@ -19,3 +21,4 @@ through.through = through

var ended = false, destroyed = false
var stream = new Stream()
var stream = new Stream(), buffer = []
stream.buffer = buffer
stream.readable = stream.writable = true

@@ -27,5 +30,24 @@ stream.paused = false

}
function drain() {
while(buffer.length && !stream.paused) {
var data = buffer.shift()
if(null === data)
return stream.emit('end')
else
stream.emit('data', data)
}
}
stream.queue = function (data) {
buffer.push(data)
drain()
}
//this will be registered as the first 'end' listener
//must call destroy next tick, to make sure we're after any
//stream piped from here.
//this is only a problem if end is not emitted synchronously.
//a nicer way to do this is to make sure this is the last listener for 'end'
stream.on('end', function () {

@@ -39,2 +61,9 @@ stream.readable = false

function _end () {
stream.writable = false
end.call(stream)
if(!stream.readable)
stream.destroy()
}
stream.end = function (data) {

@@ -46,7 +75,5 @@ if(ended) return

if(arguments.length) stream.write(data)
this.writable = false
end.call(this)
if(!this.readable)
this.destroy()
if(!buffer.length) _end()
}
stream.destroy = function () {

@@ -56,5 +83,7 @@ if(destroyed) return

ended = true
buffer.length = 0
stream.writable = stream.readable = false
stream.emit('close')
}
stream.pause = function () {

@@ -69,3 +98,7 @@ if(stream.paused) return

}
stream.emit('drain')
drain()
//may have become paused again,
//as drain emits 'data'.
if(!stream.paused)
stream.emit('drain')
}

@@ -72,0 +105,0 @@ return stream

2

package.json
{
"name": "through",
"version": "1.0.0",
"version": "1.1.0",
"description": "simplified stream contruction",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc