Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda