问题
Does node.js support writing random access?
I see this package, but it doesn't work (if I write two or more parts, the file is corrupt)
回答1:
fs core library should suffice for that. Here is the list of functions to use:
- fs.open(path, flags, [mode], callback)
- fs.write(fd, buffer, offset, length, position, callback)
- fs.writeSync(fd, buffer, offset, length, position)
- fs.read(fd, buffer, offset, length, position, callback)
- fs.readSync(fd, buffer, offset, length, position)
They are analogous to how you would do it in C.
来源:https://stackoverflow.com/questions/24230135/random-access-in-node-js