I having trouble writing array from JS, Specially with decimal values which are greater then 100.
If i use c# File.WriteAllBytes method i get different output then when I use nodejs appendFile
I am using appendFile and not writeFile because its within a loop.
I`ve taken hardcoded array for testing and this is what i got:
C#:
byte[] arr2 = new byte[] {78, 51, 49, 48, 48, 48, 85, 49, 164, 0, 67, 54, 52, 49, 53, 57, 52, 57, 52,
66, 52, 50, 49, 48, 69, 57, 70, 69, 55, 70, 50, 52, 70, 48, 69, 52, 70, 70,
50, 67, 67, 55, 50, 67, 69, 54, 53, 56, 66, 67, 53, 66};
File.WriteAllBytes("test", arr2);
JS:
const fsp = require("fs").promises;
...
...
const writeDataToFileFile = async (data: Buffer) => {
const appTempPath = app.getPath("temp");
const pathToWrite = path.join(appTempPath, "test.bin");
await fsp.appendFile(pathToWrite, `${data}`);
};
const arr = [
78, 51, 49, 48, 48, 48, 85, 49, 164, 0, 67, 54, 52, 49, 53, 57, 52, 57, 52,
66, 52, 50, 49, 48, 69, 57, 70, 69, 55, 70, 50, 52, 70, 48, 69, 52, 70, 70,
50, 67, 67, 55, 50, 67, 69, 54, 53, 56, 66, 67, 53, 66,
];
logger.info(arr);
const bufferFromArr = Buffer.from(arr);
logger.info(bufferFromArr);
await writeDataToFileFile(bufferFromArr);
M problem with JS is the � which represents the value 164, when logging the buffer.
this is the buffer: N31000U1� C64159494B4210E9FE7F24F0E4FF2CC72CE658BC5B
c# file output: N31000U1₪.C64
JS file output: N31000U1ן¿½.C64
EDIT: I figured out the c# converts the 164 into hex and then writes it, The question is how to achive this in JS