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

adhoc-stream

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

adhoc-stream

An easy way to create inline, one-off streams.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

adhoc-stream

Hmm. This stream is outputting a bunch of objects, but I really only need one of their attributes. Wouldn't it be handy if I could just do that inline...?

Yes, yes it would.

adhoc-stream is a set of utility functions for creating inline, one-off streams, without having to extend a stream object.

someModule = require "some-module"
JSONStream = require "JSONStream"
adhocStream = require "adhoc-stream"

fs.createReadStream "./path/to/some/file"
	.pipe someModule.parseThings()
	.pipe adhocStream.transformSync {objectMode: true}, (obj, encoding) ->
		@push obj.someAttribute
	.pipe JSONStream.stringify(false)
	.pipe process.stdout

API

.readable(options, func)

Instantiates a Readable stream.

  • options: Same as the options parameter for new stream.Readable.
  • func: The function to set as _read. Same function signature as for new stream.Readable.

.readableSync(options, func)

Alias for .readable. Does nothing special, because Readable streams don't need a callback in their _read method.

.writable(options, func)

Instantiates a Writable stream.

  • options: Same as the options parameter for new stream.Writable.
  • func: The function to set as _write. Same function signature as for new stream.Writable.

.writableSync(options, func)

Same as .writable, but automatically calls the callback after executing func. Useful for one-liners in CoffeeScript. Only usable when your func is completely synchronous.

.transform(options, func)

Instantiates a Transform stream.

  • options: Same as the options parameter for new stream.Transform.
  • func: The function to set as _transofmr. Same function signature as for new stream.Transform.

.transformSync(options, func)

Same as .transform, but automatically calls the callback after executing func. Useful for one-liners in CoffeeScript. Only usable when your func is completely synchronous.

Example:

fs.createReadStream "./path/to/some/file"
	.pipe adhocStream.transformSync {}, (chunk) -> @push doSomething(chunk)
...

.duplex(options, readFunc, writeFunc)

Instantiates a Duplex stream.

  • options: Same as the options parameter for new stream.Duplex.
  • readFunc: The function to set as _read. Same function signature as for new stream.Duplex.
  • writeFunc: The function to set as _write. Same function signature as for new stream.Duplex.

.duplexSync(options, readFunc, writeFunc)

Same as .duplex, but automatically calls the callback after executing writeFunc (readFunc is unaffected). Useful for one-liners in CoffeeScript. Only usable when your writeFunc is completely synchronous.

Keywords

FAQs

Package last updated on 17 Sep 2014

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