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

310
Vistas
What is the Deno equivalent of Node's Buffer.from(string, "binary")?

I found similar question here, but it lacks information about the "binary" encoding. TextEncoder is (seemingly) not an equivalent for "binary" in Deno.

Here is an example:

Deno

const str = "ºRFl¶é(÷LõÎW0 Náò8ìÉPPv\0";
const bytes = new TextEncoder().encode(str);
console.log(crypto.createHash("sha256").update(bytes).digest("hex"));

Outputs: 65e16c433fdc795b29668dc1d189b79f2b809dc4623b03c0b9c551bd83d67069

Node

const str = "ºRFl¶é(÷LõÎW0 Náò8ìÉPPv\0";
const buffer = Buffer.from(str, "binary");
console.log(crypto.createHash("sha256").update(buffer).digest("hex"));

Node outputs: fb6d4a2f86e91b13fe2d5a6d2e6ebb9b6f66e18a733b68acbf9ac3c5e56571d0

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Node's (deprecated) binary encoding is actually latin-1 (ISO-8859-1).

Assuming that your string does not use characters outside that range, you can create a byte array by converting the individual characters to their UTF-16 code unit values:

import { createHash } from "https://deno.land/std/hash/mod.ts";

const str = "ºRFl¶é(÷LõÎW0 Náò8ìÉPPv\0";
const bytes = Uint8Array.from([...str].map(c => c.charCodeAt(0)));

console.log(createHash("sha256").update(bytes).toString());

Which, as required, outputs:

fb6d4a2f86e91b13fe2d5a6d2e6ebb9b6f66e18a733b68acbf9ac3c5e56571d0
about 4 years ago · Juan Pablo Isaza Denunciar
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