file-rw

0.1.0 • Public • Published

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 files
  • options - options for fs.readFile. encoding defaults to utf-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 write
  • contents - contents to write in file
  • options - options for fs.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 for fs.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'
});

Readme

Keywords

none

Package Sidebar

Install

npm i file-rw

Weekly Downloads

145

Version

0.1.0

License

MIT

Last publish

Collaborators

  • manuelcabral