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

co-pipe

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-pipe

Wait the completion of piping.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

co-pipe

Build Status Coverage Status JavaScript Style Guide dependencies Status devDependencies Status

Wait the completion of piping.

Install

$ npm install co-pipe

Usage

Vanilla Promise

const fs = require('fs')
const pipe = require('co-pipe')

const reader = fs.createReadStream('foo.txt')
const writer = fs.createWriteStream('bar.txt')

pipe(reader, writer).then(
  () => console.log('File successfully copied.'),
  (error) => console.log(`Something was wrong with ${
    error.stream === reader ? 'reader' : 'writer'
  }`)
)

Use with co

const fs = require('fs')
const co = require('co')
const pipe = require('co-pipe')

co(function * () {
  const reader = fs.createReadStream('foo.txt')
  const writer = fs.createWriteStream('bar.txt')

  try {
    yield pipe(reader, writer)
    console.log('File successfully copied.')
  } catch (error) {
    console.log(`Something was wrong with ${
      error.stream === reader ? 'reader' : 'writer'
    }`)
  }
})

Use with koa

const fs = require('fs')
const koa = require('koa')
const pipe = require('co-pipe')

const app = koa()

app.use(function * () {
  const writer = fs.createWriteStream('foo.txt')
  yield pipe(this.req, writer)
  this.body = 'Request successfully written to foo.txt'
})

Multiple Streams

const fs = require('fs')
const zlib = require('zlib')
const pipe = require('co-pipe')

const reader = fs.createReadStream('foo.txt')
const gzip = zlib.createGzip()
const writer = fs.createWriteStream('bar.txt.gz')

pipe(reader, gzip, writer).then(
  () => console.log('File successfully gzipped.'),
  (error) => console.log(`Something was wrong with ${
    error.stream === reader ? 'reader' :
      (error.stream === gzip ? 'gzip' : 'writer')
  }`)
)

License

MIT

Keywords

FAQs

Package last updated on 27 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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