files-stream

1.0.9 • Public • Published

Files stream

The Io.js and Node.js module for concatenation files on fly. Basically for the textual files's formats only.

What's here? INSTALL USAGE API TESTS

Installation

Module can be installed either via git or via npm. Before, you have to installed io.js or node.js and git. After all, you can clone this repo (for latest version) or just run command below:

$ npm install files-stream

Example Usage

$ node example.js // in module directory
//  example.js
 
var WS            = require("fs").WriteStream;
var FSS           = require("./");
new FSS({delimiter : '\r\nI\'m between each file!\r\n', encoding  : 'ASCII'},
        './test/file.4.txt',
        './test/file.2.txt',
        './test/file.3.txt',
        './test/file.1.txt') // file does not exists
        .on("error", function (err) {
            if (err) console.log(" Ooops! \r\n",err.message);
        })
        .on('end' ,console.log.bind(console,'If there is no errors you will able to see me only once!'))
        .pipe(new WS("./my.three.files.txt"))
 

Epress integration:

// Warninig: Don't use this module in production!
// Because module haven't yet data bufferization it still remains some troubles in files reading
// process, so because you have to use this module for development only.
// See below for more info about express integration.
var express     = require('express')
var streamOf    = require('files-stream').express
var myApp       = express()
    myApp.get('/bundle.js',streamOf(''))
    myApp.listen(8080)
 

API

All module's interfaces (including options parameter and events) are inherited of the Readable stream and Events emitter classes:

 
var FSS  = require("../path to module/");
new FSS('./file/path'[,'./file/path'|options])
        .setEncoding('utf8')
        .on("readable" ,handler)
        .on("error"    ,handler)
        .on("data"     ,handler)
        .on("end"      ,handler)
// or...
new FSS(options).addFiles(['./file/path'[,'./file/path']]).on(//etc)
// For Express
var expressApp.get( /**/,FSS.express('./file/path'[,'./file/path'|options]))

Static FSS.express() method resembles the same behavior of the files-stream Class constructor but standing simple callback function.

Where options are optional and can be placed in arbitrary place of arguments order.

Possible options Default Description
options.delimiter r\n\ String-delimiter. Placed only between two files. If error occurs on some file, will be placed in order before this erroneous file
options.encoding utf8 Resembles .setEncoding() method which set up encoding to read each file

Testing

$ mocha

License

MIT.

To do

  • Bufferization
  • Express integration
  • More examples~~

npm package

Package Sidebar

Install

npm i files-stream

Weekly Downloads

21

Version

1.0.9

License

MIT

Last publish

Collaborators

  • hinell