You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
759 B
42 lines
759 B
4 years ago
|
var Stream = require("stream")
|
||
|
|
||
|
module.exports = WriteStream
|
||
|
|
||
|
WriteStream.toArray = require("./array")
|
||
|
|
||
|
function WriteStream(write, end) {
|
||
|
var stream = new Stream()
|
||
|
, ended = false
|
||
|
|
||
|
end = end || defaultEnd
|
||
|
|
||
|
stream.write = handleWrite
|
||
|
stream.end = handleEnd
|
||
|
|
||
|
// Support 0.8 pipe [LEGACY]
|
||
|
stream.writable = true
|
||
|
|
||
|
return stream
|
||
|
|
||
|
function handleWrite(chunk) {
|
||
|
var result = write.call(stream, chunk)
|
||
|
return result === false ? false : true
|
||
|
}
|
||
|
|
||
|
function handleEnd(chunk) {
|
||
|
if (ended) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ended = true
|
||
|
if (arguments.length) {
|
||
|
stream.write(chunk)
|
||
|
}
|
||
|
end.call(stream)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function defaultEnd() {
|
||
|
this.emit("finish")
|
||
|
}
|