file-rw
v0.1.0
Published
Read and write files more easily
Downloads
1,868
Readme
node-file-rw
Read and write multiple files
Installation
npm install file-rw
Usage
readFilesUtf8(files, [options], callback)
Read an array of files. options.encoding
defaults to utf-8
.
files
- an array of filesoptions
- options forfs.readFile
.encoding
defaults toutf-8
callback
- a function which will be called with(err, [ file1Contents, file2Contents, ... ])
mkWriteFile(filePath, contents, [options], callback)
Write a file, creating any directories in its path that do not exist.
filePath
- path of the file to writecontents
- contents to write in fileoptions
- options forfs.writeFile
callback
- a function which will be called with(err, filePath)
mkWriteFiles(filePairs, [options], callback)
Write a file, creating any directories in its path that do not exist.
filePairs
- an array of pairs[ filePath, contents ]
. e.g[ ['file1.txt', 'foo'], ['file2.txt', 'bar'] ]
options
- options forfs.writeFile
callback
- a function which will be called with(err, [ file1Path, file2Path, ... ])
Examples
var filerw = require('../index');
filerw.readFilesUtf8(['f1.txt', 'f2.txt'], function(err, result) {
// result[0] == f1Contents
// result[1] == f2Contents
});
filerw.mkWriteFile('a/b/c.txt', 'foo', function(err, result) {
// result == 'a/b/c.txt'
});
filerw.mkWriteFiles([[ 'a/b/c.txt', 'foo'], [ 'd/e.txt', 'bar' ]], function(err, result) {
// result[0] == 'a/b/c.txt'
// result[1] == 'd/e.txt'
});