Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
WriteBInaryFile from JS same way as C#

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!