1.0.1 • Published 4 years ago

@jacobbubu/pull-write-file v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@jacobbubu/pull-write-file

Build Status Coverage Status npm

A typescript version of pull-write-file

pull-write-file

pull-stream version of fs.createWriteStream

currently really simple and does not yet support all fs.createWriteStream options yet.

why rewriting?

  • Familiarity with the original author's intent
  • Strong type declarations for colleagues to understand and migrate to other programming languages

Example

import * as pull from 'pull-stream'
import * as fs from 'fs'
import * as path from 'path'
import osenv = require('osenv')
import writeFile from '@jacobbubu/pull-write-file'

const file = path.join(osenv.tmpdir(), 'pull-write-file_test.' + Date.now())
pull(
  pull.values([1, 2, 3, 4]),
  writeFile(file, {}, (err) => {
    const readBack = fs.readFileSync(file)
    console.log(readBack.toString()) // '1234'
    fs.unlinkSync(file)
    done()
  })
)

Performance

For large buffers this is currently as fast as node's streams, but for lots of small buffers it's a little less. Node uses the fs binding's writev to pass many buffers to the kernel simutaniously.

TODO: benchmarks with graphs comparing node streams and pull streams.

License

MIT