https://github.com/raphamorim/nbfs
NonBlocking ~Nodejs~ File System
https://github.com/raphamorim/nbfs
block extensible filesystem fs nodejs non-blocking
Last synced: about 1 year ago
JSON representation
NonBlocking ~Nodejs~ File System
- Host: GitHub
- URL: https://github.com/raphamorim/nbfs
- Owner: raphamorim
- Created: 2017-06-23T16:30:41.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-30T22:25:25.000Z (almost 9 years ago)
- Last Synced: 2025-04-20T11:19:38.464Z (about 1 year ago)
- Topics: block, extensible, filesystem, fs, nodejs, non-blocking
- Language: JavaScript
- Homepage:
- Size: 66.4 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
nbfs
NonBlocking ~Nodejs~ File System
# Why?
When running an application in NodeJS, it’s single threaded, and will only utilise a single core.
When performing cpu-intensive or a great number of tasks, you may see this impacting performance, and see runtime/respond-time increase.
If your NodeJS Application has 100% cpu-usage and is taking a long time to complete or slow to respond, this can be improved by dividing the work to be done, and spreading it over multiple processes.
### Traditional (Many tasks to a single node process)

### Distributed (Many tasks to distributed to multiple worker processes)

nbfs creates and manage multiples processes which communicate between themself. This approach helps a lot for a non-blocking nodejs architechure.
Even if you use FS native stream API or based on async ways to this job, will always run on the nodejs main thread (in idle status or not).
[Read more about it](https://medium.com/@NorbertdeLangen/communicating-between-nodejs-processes-4e68be42b917)
# Install
For install nbfs, just run in your terminal:
```bash
npm i nbfs -S
```
# Streams
## read
```js
const { read } = require('nbfs')
const stream = read('./my-file.js') // absolute path
stream.on('read', (content) => {
console.log(content) // 'abc'
})
stream.on('end', (result) => {
console.log(result) // {path: './my-file.js', content: 'abc', operation: 'read'}
})
stream.on('error', (error) => {
console.log(error)
})
```
## write
```js
const { write } = require('nbfs')
const stream = write('./my-file.js', 'hello-world') // absolute path
stream.on('write', (content) => {
console.log(content) // 'hello-world'
})
stream.on('end', (result) => {
console.log(result) // {path: './my-file.js', content: 'hello-world', operation: 'write'}
})
stream.on('error', (error) => {
console.log(error)
})
```
## Benchmark
```sh
fs.readFile x 10,738 ops/sec ±2.46% (77 runs sampled)
nbfs.read x 7,701 ops/sec ±2.74% (75 runs sampled)
fs.readFileSync x 49,473 ops/sec ±1.75% (42 runs sampled)
exec cat x 148 ops/sec ±1.57% (43 runs sampled)
```
## list
## isDirectory
## folderPath