Giter Club home page Giter Club logo

fs-tail-stream's Introduction

fs-tail-stream

fs.createReadStream that supports ongoing tailing of files

build status

The built in fs.createReadStream function stops streaming once the file has come to an end.

If you want to tail the file so that it keeps streaming data when the file grows then you're out of luck.

This module adds a { tail: true } option to the options which will keep streaming data as data is added to the file, or until the .close() method is called on the read stream.

Because this module wraps the underlying fs.createReadStream function all the options work as expected.

Installation

This module is installed via npm:

$ npm install fs-tail-stream

Example Usage

var fst = require('fs-tail-stream');
var fs = require('fs');
var ws = fs.createWriteStream(tmpFile, { flags: 'a' });

// file with the text 'hello' in it
var tmpFile = '/tmp/my-temp-file.txt';

// same parameters as `fs.createReadStream`, but pass through `tail: true`
fst.createReadStream(tmpFile, { encoding: 'utf8', start: 80, tail: true })
  .on('sync', function () {
    // called when at the end of the file
    var self = this;
    // write some new data to the file
    ws.write('world', 'utf8', function (err) {
      // stop watching for files, and let the file stream end
      // otherwise the file watching will be indefinite and the process
      // won't' exit
      self.close();
    });
  })
  // will print out both the existing contents of the file, plus the
  // newly added data
  .on('data', console.log);
  // prints out:
  //   hello
  //   world

fs-tail-stream's People

Contributors

eugeneware avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fs-tail-stream's Issues

Finally, a properly done tail

File opened only once, smart piping, code very short and clean.
This is really good!

To be closed. Just wanted to get this out of my system :)

windows support

Cool, nice little library!!
Works very good on linux but it does not seam to work on windows ๐Ÿ˜ข

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.