1.0.3 • Published 7 years ago

filemunge v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

node-filemunge

Node toolkit for recursively working with entire file trees. ###Installation   npm version

npm install filemunge

Filemunge lets you recursively (and synchronously) crawl a folder, iterate over the files, change them (without writing them back to the file system), add new ones, and then use this list of files for other purposes. This is handy if you need to put a bunch of files into S3 or into a ZIP file, but need to modify some of them first, and you don't want to write anything back to the file system. The constructor takes one argument (the folder path).

var munge = require('filemunge');

var myfiles = new munge('./dist');
myfiles.addFile('somefile.txt', new Buffer('some text'));

myfiles.iterateSync(function (filename, contents) {
  if (filename.indexOf('.js') > -1) {
    contents = contents.toString();
    contents = contents.replace(/hello world/gi, 'some other text');
    return new Buffer(contents);
  }
  // Note: you can also remove a file here by returning false
});
myfiles.iterateSync(function (filename, contents) {
  // upload to s3
});
myfiles.iterate(function(filename, contents) {
  // Asynchronous iteration
});

To convert the resulting collection of files and folder to a zip (Buffer) call toZipBuffer():

var buf = myfiles.toZipBuffer();