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

167
Views
Cloudflare Workers Buffer.from()

I am not that familiar with how Buffers and all that work.

In node I can do

const str = "dasjkiodjsiodjpasiodfjodifjaspiofjsdioajfpasodfjsdioa";
let buff = Buffer.from(str); // <Buffer 64 61 73 6a 6b 6 etc...
let buffHex = Buffer.from(str, 'hex');

console.log(buff)

How would I go about doing this in Cloudflare Workers, because I get ReferenceError: Buffer is not defined

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Buffer is a Node API. Cloudflare Workers is based on web platform APIs instead, like what you'd find in browsers. The web platform alternative to Buffer is Uint8Array. You can use the TextEncoder and TextDecoder APIs to convert between Uint8Arrays with UTF-8 encoding and text strings.

let bytes = new TextEncoder().encode(str);

To convert a Uint8Array to hex, you can use a function like:

function bytes2hex(bytes) {
  return Array.prototype.map.call(bytes,
      byte => ('0' + byte.toString(16)).slice(-2)).join('');
}

I do not recommend using a Buffer polyfill for this as it'll bloat your code size. It's better to use Uint8Array directly.

In general you should be able to find answers about how to do common operations on Uint8Array on Stack Overflow.

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!