0.0.1 • Published 7 years ago

qufy v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

qufy

A basic queue system to control file system operations

npm npm

Install

Use npm to install this module in your project:

npm install --save qufy

Usage

//Import qufy 
var qufy = require('qufy');

//File to manage 
var file1 = './my-file.txt';

//Write to the file 
// This will register a new queue associated to `file1`, and will add this write task.
// Also, this task will be executed directly because there is not waiting tasks on this queue.
qufy.write(file1, 'data-to-write', 'utf8', function(error)
{
  console.log('Write task to file1 done!');
});

//Append data to the file
// This will be added to the queue associated to `file1`. When the previous write task is 
// completed, this task will be executed.
qufy.append(file1, 'more-data', 'utf8', function(error)
{
  console.log('Append task to file1 done!');
});

//Read the file 
// This will be added to the queue associated to `file1`. When the previous append task is
// completed, this task will be executed.
qufy.read(file1, 'utf8', function(error, data)
{
  console.log('Read task to file1 done!');
});

//Another file 
var file2 = './my-file-2.txt';

//Write task to file2
// This will create a new task associated to `file2`. This queue is independent of the queue associated 
// with `file1`, because paths are not equals.
qufy.write(file2, 'data-to-write', 'utf8', function(error)
{
  console.log('Write task fo file2 done!');
});

This will print in console:

Write task to file1 done!
Write task to file2 done!
Append task to file1 done!
Read task to file1 done!

API

qufy.append(path, data[, options], callback)

Same API than fs.appendFile.

This method will create an append to file task in the queue associated to path.

qufy.read(path[, options], callback)

Same API than fs.readFile.

This method will create a read file task in the queue associated to path.

qufy.write(path, data[, options], callback)

Same API than fs.writeFile.

This method will create a write file task in the queue associated to path.

qufy.cancel(path)

Stop the queue associated to path.

License

MIT © Josemi Juanes.

0.0.1

7 years ago