write-file-tree
write an object to nested file tree, with one file for each value
Last updated 3 years ago by goto-bus-stop .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install write-file-tree 
SYNC missed versions from official npm registry.

write-file-tree

write an object to nested file tree, with one file for each value

npm travis standard

Install

npm install write-file-tree

Usage

var writeFileTree = require('write-file-tree')

writeFileTree('/path/to/directory', {
  'index.html': '<!DOCTYPE html><html>...',
  'bundle.js': getMyBundle()
}, function (err) {
  if (err) console.error('failed')
})

API

writeFileTree(basedir, tree[, opts], cb)

Recursively write each value in the tree object to a directory basedir. opts can be an object:

  • opts.encoding - encoding to pass to fs.writeFile()
  • opts.limit - max amount of i/o operations to run simultaneously. default 5.

cb is a node-style callback receiving an error in the first parameter. Object keys in the tree object are file names, while values are the file contents. Nested directories have another tree object as their value. For example, the test/fixture directory can be written by using this object:

writeFileTree('test/fixture', {
  'one.js': '1;\n',
  'two.js': '2;\n',
  a: {
    b: {
      'c.txt': 'this is c\n',
      c: {
        'd.txt': 'file d\n' } } }
}, cb)

writeFileTree.sync(basedir, tree[, opts])

The same, but sync.

License

Apache-2.0

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 3
Dependencies (2)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |