Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

thunks/thunk-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thunk-stream

Wrap a readable/writable/duplex/transform stream to a thunk.

NPM version Build Status Downloads

Demo

const thunkStream = require('thunk-stream')
const stream = require('stream')
const fs = require('fs')

const readableStream = fs.createReadStream('index.js')
const passStream = new stream.PassThrough()

thunkStream(readableStream)(function (error) {
  if (error) console.error('error', error)
  else console.log('read file end.')
})

thunkStream(passStream)(function (error) {
  console.log('file pass through finished.')
})

readableStream.pipe(passStream)

Installation

npm install thunk-stream

API

const thunkStream = require('thunk-stream')

thunkStream(stream[, options])

Return a thunk function.

stream

Required, Type: stream, readable/writable/duplex/transform stream.

options.endEventType

Optional, Type: String or Array

Appoint one or more event types to delegate the stream end. In built end event types: ['end', 'finish', 'close', 'error'].

options.error

Optional, Type: Boolean

If true, ignore error event for stream end.

options.end

Optional, Type: Boolean

If true, ignore end event for stream end.

options.finish

Optional, Type: Boolean

If true, ignore finish event for stream end.

options.close

Optional, Type: Boolean

If true, ignore close event for stream end.

options[eventType]

Optional, Type: Boolean

If true, ignore eventType event for stream end.

thunk.clearListeners()

After thunk is called, clearListeners is added that can remove all listeners added to stream by thunkStream. if listeners has been removed already, it return false, else return true.

About

Wrap a readable/writable/duplex/transform stream to a thunk

Resources

License

Stars

Watchers

Forks

Packages

No packages published