append-only-live-stream

0.0.5 • Public • Published

append-only-live-stream

build status AppVeyor Build Status


Create a live stream from an append-only file.


Get it!

npm install --save append-only-live-stream

Usage

var { createWriteStream, unlink, writeFile } = require('fs')
var createLiveStream = require('./index')
var assert = require('assert')
 
writeFile('./some.usage', '', function (err) {
  if (err) throw err
 
  var appendStream = createWriteStream('./some.usage', { flags: 'a' })
  var liveStream = createLiveStream('./some.usage')
 
  var crunch = ''
  var expected = 'ACAB'
  var input = expected.split('')
 
  liveStream.on('data', function (chunk) {
    var txt = chunk.toString()
    console.log(txt)
    crunch += txt
  })
 
  appendStream.write(input.shift(), function () { // A
    appendStream.write(input.shift(), function () { // C
      appendStream.write(input.shift(), function () { // A
        appendStream.write(input.shift(), function () { // B
          setTimeout(function () {
            assert.ok(crunch === expected, 'ACAB')
            unlink('some.usage', function () {})
          }, 1500)
        })
      })
    })
  })
 
})

API

createLiveStream(file[, opts])

Create a readable stream from an append-only file and get live updates of appends. file indicates an append-only file. Options get passed on to the stream.Readable constructor and fs.watch. opts defaults to:

{
  encoding: null // decode buffers to strings using encoding
  highWaterMark: 16384 // readable streams highWatermark
  persistent: false // keep process alive while watching?
}

License

MIT

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i append-only-live-stream

    Weekly Downloads

    4

    Version

    0.0.5

    License

    MIT

    Unpacked Size

    10.1 kB

    Total Files

    9

    Last publish

    Collaborators

    • chiefbiiko