Detalhes do pacote

read-file-tree

goto-bus-stop29MIT1.1.2

recursively read contents of all files in a directory

directory, fs

readme (leia-me)

read-file-tree

recursively read contents of all files in a directory

npm travis standard

Install

npm install read-file-tree

Usage

var readFileTree = require('read-file-tree')

readFileTree('/path/to/directory', function (err, tree) {
  console.log(tree)
})

API

readFileTree(basedir[, opts], cb)

Recursively read contents of all files in the directory basedir. opts can be an object:

  • opts.encoding - encoding to pass to fs.readFile(), by default a Buffer is returned

cb is a node-style callback receiving an error in the first parameter, and a tree object in the second. 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 results in this object:

{ 'one.js': '1;\n',
  'two.js': '2;\n',
  a: {
    b: {
      'c.txt': 'this is c\n',
      c: {
        'd.txt': 'file d\n' } } } }

readFileTree.sync(basedir[, opts])

The same, but sync. Returns tree.

See Also

  • write-file-tree - write an object to nested file tree, with one file for each value
  • flat - flatten and unflatten objects—you can use this to create an object with relative paths as keys:
    flat(readFileTree('./dest'), { delimiter: '/' })
    // { 'a.txt': '',
    //   'some/dir/name/b.txt': '' }
    

License

MIT

changelog (log de mudanças)

read-file-tree change log

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

1.1.2 - 2019-10-09

  • Call the cb in the async API when there are empty directories

1.1.1 - 2018-09-20

  • Add "See Also" section in readme
  • Test on Node.js 4-10

1.1.0 - 2017-09-22

  • Sync version as require('read-file-tree').sync

1.0.0 - 2017-09-16

  • Initial release.