Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reduplexer

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reduplexer - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

36

index.js

@@ -33,10 +33,8 @@ /*

this._firstPayloadMethod = 'write'
this.on('finish', function() {
if (this._writable)
return this._writable.end()
this._writable.end()
})
this._firstPayloadMethod = 'end'
})
this._lastReadCallback = null
}

@@ -46,2 +44,12 @@

function callWrite2Args(chunk, enc, cb) {
this._writable.write(chunk, enc)
cb()
return true
}
function callWrite3Args(chunk, enc, cb) {
return this._writable.write(chunk, enc, cb)
}
ReaDuplexer.prototype.hookWritable = function hookWritable(writable) {

@@ -62,4 +70,10 @@ var that = this

if (this._writable.write.length === 3) {
this._callWrite = callWrite3Args
} else {
this._callWrite = callWrite2Args
}
if (this._firstPayload) {
this._writable[this._firstPayloadMethod](
this._callWrite(
this._firstPayload.chunk

@@ -69,2 +83,6 @@ , this._firstPayload.enc

if (this._writableState.ended) {
this._writable.end()
}
delete this._firstPayload

@@ -123,5 +141,9 @@ }

ReaDuplexer.prototype._callWrite = function nop() {
throw new Error('hook Writable to use')
}
ReaDuplexer.prototype._write = function write(chunk, enc, cb) {
if (this._writable)
return this._writable.write(chunk, enc, cb)
this._callWrite(chunk, enc, cb)

@@ -128,0 +150,0 @@ // we are in delayed open

2

package.json
{
"name": "reduplexer",
"version": "0.0.4",
"version": "0.0.5",
"description": "Another Stream2 duplexer",

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

var test = require('tap').test
, stream = require('readable-stream')
, duplexer = require('./')
var test = require('tap').test
, stream = require('readable-stream')
, duplexer = require('./')
, http = require('http')

@@ -235,1 +236,77 @@ test('basically works', function(t) {

})
test('HTTP support', function(t) {
t.plan(1)
var server = http.createServer()
, instance = duplexer()
function handle(req, res) {
req.pipe(res)
}
server.on('request', handle)
server.on('listening', function() {
var request = http.request({
host: 'localhost'
, port: server.address().port
, method: 'POST'
, path: '/'
})
request.on('response', function(res) {
instance.hookReadable(res)
})
instance.hookWritable(request)
instance.end('a message')
})
server.listen(0)
instance.on('data', function(chunk) {
t.equal(chunk.toString(), 'a message')
server.close()
})
})
test('HTTP support with delayed open', function(t) {
t.plan(1)
var server = http.createServer()
, instance = duplexer()
function handle(req, res) {
req.pipe(res)
}
server.on('request', handle)
server.on('listening', function() {
var request = http.request({
host: 'localhost'
, port: server.address().port
, method: 'POST'
, path: '/'
})
request.on('response', function(res) {
instance.hookReadable(res)
})
instance.hookWritable(request)
})
server.listen(0)
instance.on('data', function(chunk) {
t.equal(chunk.toString(), 'a message')
server.close()
})
instance.end('a message')
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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