Giter VIP home page Giter VIP logo

node-file-size-watcher's Introduction

node-file-size-watcher

This project is no longer being updated or maintained.

Watches files for size changes in Node.js. Tiny, unit tested, and no dependencies.

###Usage

require('file-size-watcher').watch("fileName.txt").on('sizeChange',
	function callback(newSize, oldSize){
		console.log('The file size changed from ' + oldSize + ' to ' + newSize);
	}
);

The watch method returns an EventEmitter. It takes the following parameters:

watch(fd, [interval], [onErr], [onReady])

  • fd - File descriptor (anything fs.stat accepts for a file descriptor)
  • interval - pause between checks in milliseconds.
  • onErr - Error handler. Users can listen for 'error' events themselves, but setting this avoids possible race conditions.
  • onReady - Same thing as onErr, but for 'ready' event.

###Events

  • 'sizeChange' - passes new size and old size to listeners.
  • 'ready' - passes initial size to listeners (called only once).
  • 'error' - Passes any error objects to listeners. Includes ENOENTs, so prepare for lots of those if the file is missing. Program will keep running regardless of whether this is listened to.

###Extras

The watcher object (var watcher = fsw.watch(...)), besides emitting events, also has a few additional features:

	watcher.stop(); // Stops watching the file
	watcher.start(); // Resumes watching the file
	console.log(watcher.info.size); // Returns last known size.

node-file-size-watcher's People

Contributors

alexmiddeleer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

varadarajana

node-file-size-watcher's Issues

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.