https://github.com/semibran/fs-tree
:evergreen_tree: speedy recursive reads and writes for simple file system trees
https://github.com/semibran/fs-tree
file-system filesystem fs recursive tree
Last synced: 11 months ago
JSON representation
:evergreen_tree: speedy recursive reads and writes for simple file system trees
- Host: GitHub
- URL: https://github.com/semibran/fs-tree
- Owner: semibran
- License: mit
- Created: 2018-03-01T09:19:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-19T00:36:57.000Z (over 5 years ago)
- Last Synced: 2025-07-14T14:50:42.166Z (11 months ago)
- Topics: file-system, filesystem, fs, recursive, tree
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# fs-tree
> speedy recursive reads and writes for simple file system trees
```js
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.txt
```
In this scenario, `read("foo", callback)` might yield the following:
```js
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
[![npm badge]][npm package]
### `read(path[, opts], callback(err, data))`
Reads the file or folder specified by `path` and returns its data via `callback`.
```js
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.
```js
write(path, data, err => {
if (err) throw err
console.log("write successful")
})
```
## related
* [`semibran/scaffy`][semibran/scaffy]: tiny project scaffolding tool
[npm badge]: https://nodei.co/npm/@semibran/fs-tree.png?mini
[npm package]: https://npmjs.com/package/@semibran/fs-tree
[semibran/scaffy]: https://github.com/semibran/scaffy