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

stream-to-pull-stream

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-to-pull-stream - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

test/sink.js

32

index.js

@@ -18,13 +18,19 @@ var pull = require('pull-core')

function write(read, stream) {
var ended
function write(read, stream, cb) {
var ended, closed = false
function done (end) {
cb && cb(end === true ? null : end)
}
function onClose () {
if(closed) return
closed = true
cleanup()
if(!ended) read(ended = true, function () {})
if(!ended) read(ended = true, done)
}
function onError (err) {
cleanup()
if(!ended) read(ended = err, function () {})
if(!ended) read(ended = err, done)
}
function cleanup() {
stream.on('finish', onClose)
stream.removeListener('close', onClose)

@@ -34,2 +40,3 @@ stream.removeListener('error', onError)

stream.on('close', onClose)
stream.on('finish', onClose)
stream.on('error', onError)

@@ -40,5 +47,6 @@ process.nextTick(function next() {

return stream._isStdio || stream.end()
if(ended = ended || end)
return stream.emit('error', end)
if(ended = ended || end) {
if(stream.destroy) stream.destroy()
else return cb(ended)
}
var pause = stream.write(data)

@@ -147,5 +155,5 @@ if(pause === false)

var sink = function (stream) {
var sink = function (stream, cb) {
return pull.Sink(function (read) {
return write(read, stream)
return write(read, stream, cb)
})()

@@ -158,3 +166,3 @@ }

exports = module.exports = function (stream) {
exports = module.exports = function (stream, cb) {
return (

@@ -164,6 +172,6 @@ stream.writable

? pull.Through(function(_read) {
write(_read, stream);
write(_read, stream, cb);
return read(stream)
})()
: sink(stream)
: sink(stream, cb)
: source(stream)

@@ -170,0 +178,0 @@ )

{
"name": "stream-to-pull-stream",
"description": "convert a stream1 or streams2 stream into a pull-stream",
"version": "1.3.1",
"version": "1.4.0",
"homepage": "https://github.com/dominictarr/stream-to-pull-stream",

@@ -14,4 +14,5 @@ "repository": {

"devDependencies": {
"through": "~2.2.7",
"tape": "~0.3.3"
"through": "~2.3.4",
"tape": "~2.13.1",
"pull-stream": "~2.23.0"
},

@@ -18,0 +19,0 @@ "scripts": {

@@ -12,5 +12,10 @@ # stream-to-pull-stream

toPullStream(fs.createReadStream(__filename))
.pipe(pull.map(function (e) { return e.toString().toUpperCase() }))
.pipe(toPullStream(process.stdout))
pull(
toPullStream.source(fs.createReadStream(__filename)),
pull.map(function (e) { return e.toString().toUpperCase() }),
toPullStream.sink(process.stdout, function (err) {
if(err) throw err
console.log('done')
})
)
```

@@ -17,0 +22,0 @@

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