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'); // Error
libfs
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.
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.persistent
option 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 onlychange
andrename
events, wheninotify(7)
provides a much more diverse event set, so the mapping tochange
andrename
might be a bit off. It internally usesInotify
class fromlibaio
package, for more control and better performance use thelibaio.Inotify
class instead.readdir()
results may differ aslibfs
implements it itself instead of usinglibc
's C implementation.realpath()
results may differ aslibfs
implements it itself instead of usinglibc
's C implementation.fs.ReadStream
andfs.WriteStream
are not implemented yet.