Skip to content

alexsaves/node-filemunge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

Node toolkit for recursively working with entire file trees.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published