1.2.0 • Published 5 years ago
@semibran/fs-tree v1.2.0
fs-tree
speedy recursive reads and writes for simple file system trees
const { read, write } = require("@semibran/fs-tree")
read(src, (err, data) => {
if (err) throw err
write(dest, data, (err) => {
if (err) throw err
console.log(`copied from ${src} to ${dest}`)
})
})fs-tree provides fast recursive read and write operations for both files and folders by modelling them as strings and maps respectively. For example, consider the following folder structure:
foo
└── bar
├── hello.txt
└── world.txtIn this scenario, read("foo", callback) might yield the following:
foo = {
"bar": {
"hello.txt": "greetings human",
"world.txt": "welcome to mars"
}
}Furthermore, read("foo/bar/hello.txt", callback) would yield "greetings human", equivalent to the output of fs.readFile called with the "utf8" option.
Note that this module doesn't handle any kinds of links for simplicity's sake, although this property is subject to change.
usage
read(path[, opts], callback(err, data))
Reads the file or folder specified by path and returns its data via callback.
read(path, (err, data) => {
if (err) throw err
console.log(path + ": " + JSON.stringify(data, null, 2))
})opts
ignore: file names and file extensions to ignore, e.g.[ ".git", ".png" ]
write(path, data, callback(err))
Writes data to the given path, calling callback upon completion.
write(path, data, err => {
if (err) throw err
console.log("write successful")
})related
semibran/scaffy: tiny project scaffolding tool
