Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js - the best way to replace content in buffer

Tags:

node.js

buffer

I am reading a file to buffer like:

var myfile = fs.readFileSync(myfile.txt);

What is the proper way to replace some string to another in myfile buffer? I would like to keep it as buffer, because it is faster than to keep it as string.

like image 702
Flash Thunder Avatar asked Aug 19 '13 12:08

Flash Thunder


People also ask

Which of the options is a valid way of creating a buffer in Node JS?

var buf = new Buffer("Simply Easy Learning", "utf-8"); Though "utf8" is the default encoding, you can use any of the following encodings "ascii", "utf8", "utf16le", "ucs2", "base64" or "hex".

Is buffer deprecated?

Buffer() is deprecated due to security and usability issues (v2. 0.0)

Which method is used to copy sub buffers of a Node buffer?

js buffer copy() Method.

What does the BUF toJSON () method return in node JS?

The toJSON() method returns a JSON object based on the Buffer object.


1 Answers

The package buffer-replace https://www.npmjs.com/package/buffer-replace replaces content in a buffer like the function replace for String.

like image 53
christegho Avatar answered Oct 19 '22 09:10

christegho