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 |
{ | ||
"name": "reduplexer", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Another Stream2 duplexer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
83
test.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
300803
337
5