Hello. As I am not strong in node.js, I ask for help.

There is a binary file to read. I faced that I do not know how to read string. Can you help me with this question?

Here is my example:

var fs = require("fs"); fs.readFile('file.data', '', function(err, data) { if (err) throw err; var p = 0; console.log(data.readInt16LE(p));p+=2; console.log(data.readInt16LE(p));p+=2; console.log(data.readInt32LE(p));p+=4; var len = data.readInt32LE(p);p+=4; for (var i = 0; i < len; i++ ){ data.readInt32LE(p); p+=4; data.readString(64, p); p+=64; //Вот тут мне нужно прочитать string длинной 64 data.readInt32LE(p); p+=4; data.readInt32LE(p); p+=4; data.readInt32LE(p); p+=4; } console.log(data.readInt32LE(p));p+=4; console.log(data); console.log(p); }); 
  • And if you just do - data.readString (64, p) .toString (); - pnp2000
  • TypeError: data.readString is not a function I have already tried everything. I thought maybe there can be a library, which would be so read. Could not find anything. - Jony Kook
  • and if you read it like this buf.readDoubleLE (p) .toString (); I’m not a monster of buffer theory, I’d have a date on my hands, and it’s hard for me to give the right answer right away. - pnp2000

0