New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

writsy

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

writsy

Write stream wrapper that supports async initialization and flush function

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

writsy

Write stream wrapper that supports async initialization and flush function.

Build Status

npm install writsy

var ws = writsy([opts])

var ws = writsy.obj([opts])

Wraps a new writable stream (or object stream) by passing init callback function. Supports optional flush function that is called before 'finish' emitted.

var writsy = require('writsy')
...

var ws = writsy({
  init (cb) {
    // async initialization, error handling
    mkdirp('/tmp/foo/', (err) => {
      if (err) return cb(err)
      cb(null, fs.createWriteStream('/tmp/foo/bar.txt'))
    })
  },
  flush (cb) {
    // flush before finish
    fs.rename('/tmp/foo/bar.txt', './dest.txt', cb)
  }
})

fs.createReadStream('loremipsum.txt').pipe(ws)

Or class inheritance by setting _init and _flush methods:

var Writsy = require('writsy')

class Writer extends Writsy {
  constructor (opts) {
    super(opts)
  }
  _init (cb) {
    // async initialization, error handling
    mkdirp('/tmp/foo/', (err) => {
      if (err) return cb(err)
      cb(null, fs.createWriteStream('/tmp/foo/bar.txt'))
    })
  }
  _flush (cb) {
    // flush before finish
    fs.rename('/tmp/foo/bar.txt', './dest.txt', cb)
  }
}

fs.createReadStream('loremipsum.txt').pipe(new Writer())

License

MIT

FAQs

Package last updated on 27 Mar 2017

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