Am I missing something or does node.js's standard file I/O module lack analogs of the usual file random access methods?
seek()
/fseek()
tell()
/ftell()
How does one read random fixed-size records from large files in node without these?
Am I missing something or does node.js's standard file I/O module lack analogs of the usual file random access methods?
seek()
/ fseek()
tell()
/ ftell()
How does one read random fixed-size records from large files in node without these?
Use this:
Then this:
Read this for details:
https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback
I suppose that createReadStream creates new file descriptor over and over. I prefer sync version:
}
node doesn't have these built in, the closest you can get is to use
fs.createReadStream
with astart
parameter to start reading from an offset, (pass in an existingfd
to avoid re-opening the file).http://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options
tell
is not, but it is pretty rare to not already know the position you are at in a file, or to not have a way to keep track yourself.seek
is exposed indirectly via theposition
argument offs.read
andfs.write
. When given, the argument will seek to that location before performing its operation, and ifnull
, it will use whatever previous position it had.