end-of-stream
Advanced tools
Comparing version 0.1.0 to 0.1.1
20
index.js
@@ -5,8 +5,4 @@ var once = require('once'); | ||
var patch = function(stream, fn) { // ensure a 'finish' event - even for 0.8 streams | ||
var end = stream.end; | ||
stream.end = function() { | ||
fn(); | ||
end.apply(this, arguments); | ||
}; | ||
var isRequest = function(stream) { | ||
return stream.setHeader && typeof stream.abort === 'function'; | ||
}; | ||
@@ -25,2 +21,6 @@ | ||
var onlegacyfinish = function() { | ||
if (!stream.writable) onfinish(); | ||
}; | ||
var onfinish = function() { | ||
@@ -41,3 +41,9 @@ writable = false; | ||
if (writable && !ws) patch(stream, onfinish); | ||
if (isRequest(stream)) { | ||
stream.on('complete', onfinish); | ||
stream.on('abort', onclose); | ||
} else if (writable && !ws) { // legacy streams | ||
stream.on('end', onlegacyfinish); | ||
stream.on('close', onlegacyfinish); | ||
} | ||
@@ -44,0 +50,0 @@ stream.on('end', onend); |
{ | ||
"name": "end-of-stream", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Call a callback when a readable/writable/duplex stream has completed or failed.", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/mafintosh/end-of-stream.git", |
4131
91