JSPM

  • Created
  • Published
  • Downloads 6435345
  • Score
    100M100P100Q223510F
  • License MIT

A streaming way to send data to a Node.js Worker Thread

Package Exports

  • thread-stream

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (thread-stream) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

thread-stream

A streaming way to send data to a Node.js Worker Thread.

install

npm i thread-stream

Usage

'use strict'

const ThreadStream = require('thread-stream')
const { join } = require('path')

const stream = new ThreadStream({
  filename: join(__dirname, 'worker.js'),
  workerData: { dest }
})

stream.write('hello')
stream.flush(function () {
  stream.write(' ')
  stream.write('world')
  stream.flushSync()
  stream.end()
})

In worker.js:

'use strict'

const fs = require('fs')
const { once } = require('events')

async function run (opts) {
  const stream = fs.createWriteStream(opts.dest)
  await once(stream, 'open')
  return stream
}

module.exports = run

License

MIT