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

172
Vistas
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 Respuestas
Responde la pregunta

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