Continuous reading or writing to a file using random offsets and lengths
npm install random-access-file
If you are receiving a file in multiple pieces in a distributed system it can be useful to write these pieces to disk one by one in various places throughout the file without having to open and close a file descriptor all the time.
random-access-file allows you to do just this.
var randomAccessFile =var file =file
file will use an open file descriptor. When you are done with the file you should call
Create a new file. Options include:
truncate: false // truncate the file before reading / writinglength: someLength // truncate the file to this size firstreadable: true // should the file be opened as readable?writable: true // should the file be opened as writable?
Write a buffer at a specific offset.
Read a buffer at a specific offset. Callback is called with the buffer read.
Will truncate the file if offset + length is larger than the current file length. Is otherwise a noop.
Call this method when the entire file has been written. Options include:
mtime: mtime // set the file's mtimeatime: atime // set the file's atime
Close the underlying file descriptor.
Unlink the underlying file.
Emitted when the file descriptor has been opened. You can access the fd using
You do not need to wait for this event before doing any reads/writes.
Emitted when the file has been closed.