2.0.0 • Published 9 years ago

stream-as-promised v2.0.0

Weekly downloads
3
License
Unlicense
Repository
github
Last release
9 years ago

Stream as Promise(d)

input = fs.createReadStream('/etc/passwd')
output = fs.createWriteStream('/dev/null')
input.pipe(output)

These complete at the end of each stream:

stream_as_promised(input)
.then(function(){
  console.log("Done reading.");
})

stream_as_promised(output)
.then(function(){
  console.log("Done writing.");
})

One might also detect individual events on a stream:

stream_as_promised(input)
.once('end')
.then(function(){
  console.log("Done reading.");
})

The original stream is always available, so even though you cannot use the stream-as-promised as a replacment for the stream, you can still use it as storage for it:

var w = stream_as_promised(fs.createWriteStream('/dev/null'))
w
.once('drain')
.then(function(){
  w.stream.write(some_chunk);
})

The stream is actually a promisified version of the stream:

var w = stream_as_promised(fs.createWriteStream('/dev/null'))
w.stream.writeAsync(chunk)
.then(function(){
  w.stream.writeAsync(some_chunk)
})
.then(function(){
  w.stream.writeAsync(some_other_chunk)
})

Install

npm install stream-as-promised
2.0.0

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago