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

319
Views
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 answers
Answer question

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 Report
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!