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

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -