Wednesday, 10 May 2017

Create or Open file then write data at a specific position

I have a filename, an offset into the file, and a byte of data and I need to write a function to store the byte of data at the offset in the file. It needs to create the file if it does not exist but open the existing one if not. It needs to add the data at the specified location in the file, extending it if necessary.

However none of the options to fs.openFile seem to work. They either fail if the file doesn't exist, truncate the file if it already exists, or do not allow "seek" to write data at a position in the file using the offset in a write.

How can I achieve what I need? This is using nodejs on Linux.



via jcoder

No comments:

Post a Comment