fslib v1.0.0
libfs
fs.js module written in pure JavaScript. Has no native dependencies other
than syscall function from libsys.
When you require libjs for the first time it has only synchronous methods:
var libfs = require('libfs');
libfs.openSync('file.txt'); // OK
libfs.open('file.txt'); // Errorlibfs implements asynchronous methods in a few different ways, so
you have to choose which implementation you want to use. After you have chosen
once, the asynchronous functions will stay attached with the libfs object forever, so
you have to do this only once.
useFake() will create fake async wrappers around the blocking fs functions.
This is useful when you don't want to introduce new dependencies, but just want
a quick way to conform with fs.js API, usage:
libfs.useFake(libfs);useTagg() will use thread-a-go-go to execute async calls in a thread pool, similar
to what libuv does. NOT IMPLEMENTED YET.
useLibaio will use Linux's async io_submit system calls. NOT IMPLEMENTED YET.
Incompatibilities with Node.js
libfs implements fs.js API as in the docs,
with few minor differences, here are the known ones:
- Some error messages may be different.
utimes()sets file time in seconds, instead of milliseconds.futimes()is not implemented.persistentoption inwatchFile()andwatch()methods is alwaystrue, even if you set it tofalse, as I don't know how to detect if there are no more events in node's event loop, maybe somebody does know?watch()function is implemented using the sameinotify(7)system calls that Node.js is using, however, I don't know why Node.js emits onlychangeandrenameevents, wheninotify(7)provides a much more diverse event set, so the mapping tochangeandrenamemight be a bit off. It internally usesInotifyclass fromlibaiopackage, for more control and better performance use thelibaio.Inotifyclass instead.readdir()results may differ aslibfsimplements it itself instead of usinglibc's C implementation.realpath()results may differ aslibfsimplements it itself instead of usinglibc's C implementation.fs.ReadStreamandfs.WriteStreamare not implemented yet.
9 years ago