node.js - Positional write to existing file [Linux, NodeJS] -
i'm trying edit existing binary file using nodejs.
my code goes this:
file = fs.createwritestream("/path/to/existing/binary/file", {flags: "a"}); file.pos = 256; file.write(new buffer([0, 1, 2, 3, 4, 5]));
in os x, works expected (the bytes @ 256..261
replaced 0..5
).
in linux however, 5 bytes appended end of file. mentioned in nodejs api reference:
on linux, positional writes don't work when file opened in append mode. kernel ignores position argument , appends data end of file.
how around this?
open mode of r+
instead of a
. r+
portable way want read and/or write arbitrary positions in file, , file should exist.
Comments
Post a Comment