ofs

0.1.0 • Public • Published

OFS

Optimized ~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)


Traditional

Distributed (Many tasks to distributed to multiple worker processes)


Distributed

ofs 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

Install

For install ofs, just run in your terminal:

npm i ofs -S

Streams

read

const { read } = require('ofs')
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

const { write } = require('ofs')
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)
})

list

isDirectory

folderPath

Package Sidebar

Install

npm i ofs

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • raphamorim