Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda