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

catchment

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

catchment

Collect stream data into a catchment.

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-21.48%
Maintainers
1
Weekly downloads
 
Created
Source

catchment

npm version

Collect stream data into a catchment.

npm i catchment

ES5

The package uses some newer language features. For your convenience, it's been transpiled to be compatible with Node 4. You can use the following snippet.

const catchment = require('catchment/es5')

API

Catchment extends Writable, and pushes incoming data into an array. When the stream is finished, (e.g., .end() is called), a promise from .promise property is fulfilled with joined data. If an error occurred, the promise is rejected.

options are passed down to the extend Writable (super(options)).

Catchment(options: object)

const { Readable } = require('stream')
const Catchment = require('catchment')

const data = 'test-data'
const catchment = new Catchment()

const rs = new Readable({
    read() {
        for (let i = 0; i < data.length; i++) {
            const c = data.charAt(i)
            this.push(c)
        }
        this.push(null)
    },
})
rs.pipe(catchment);

(async () => {
    const res = await catchment.promise
    console.log(res) // test-data
})()

options.rs: Readable

You can pass a Readable stream which will be automatically piped into the Catchment.

const { Readable } = require('stream')
const Catchment = require('catchment')

const data = 'test-data'

const rs = new Readable({
    read() {
        for (let i = 0; i < data.length; i++) {
            const c = data.charAt(i)
            this.push(c)
        }
        this.push(null)
    },
})

const catchment = new Catchment({ rs });

(async () => {
    const res = await catchment.promise
    console.log(res) // test-data
})()

options.binary: boolean

If you would like the result as Buffer, pass the binary option.

const { Readable } = require('stream')
const Catchment = require('catchment')

const data = 'test-data'

const rs = new Readable({
    read() {
        for (let i = 0; i < data.length; i++) {
            const c = data.charAt(i)
            this.push(c)
        }
        this.push(null)
    },
});

(async () => {
    const catchment = new Catchment({ binary: true })
    rs.pipe(catchment)

    const res = await catchment.promise
    console.log(res) // <Buffer 74 65 73 74 2d 64 61 74 61>
})()

(c) 2018 sobesednik.media

Keywords

FAQs

Package last updated on 02 Jan 2018

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