Socket
Socket
Sign inDemoInstall

callback2stream

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callback2stream

Transform sync, async or generator function to Stream. Correctly handle errors and optional arguments.


Version published
Weekly downloads
7
increased by250%
Maintainers
1
Weekly downloads
 
Created
Source

callback2stream npmjs.com The MIT License npm downloads

Transform sync, async or generator function to Stream. Correctly handle errors and optional arguments.

code climate standard code style travis build status coverage status dependency status

Install

npm i callback2stream --save

Usage

For more use-cases see the tests

const callback2stream = require('callback2stream')

callback2stream

Create a stream from sync, async or generator function.

Params

  • fn {Function}: Any kind of function.
  • opts {Object}: Directly passed to through2 from promise2stream.
  • returns {Function}: That when executed, returns transform stream, coming from promise2stream, using through2.

Example

var fs = require('fs')
var cb2stream = require('callback2stream')

var readFileStream = cb2stream(fs.readFile)
var stream = readFileStream('package.json', 'utf8')
stream
  .on('data', function (val) {
    var json = JSON.parse(val)
    console.log(json.name) // => 'callback2stream'
  })
  .once('error', console.error)
  .once('end', function () {
    console.log('reading finished')
  })

// you also have access to the
// contents with promise
stream.promise
  .then(JSON.parse, console.error)
  .then(function (val) {
    console.log(val.name) // => 'callback2stream'
  }, console.error)
  .catch(console.error)

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Keywords

FAQs

Package last updated on 06 May 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