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

267
Vistas
How to convert an arrayBuffer to readableStream in typescript?

I'm using Pinata's pinFileToIPFS() function that requires a ReadableStream to upload to Pinata's IPFS nodes. I have the bytearray of the file, for example of a PNG. I want to convert this byteArray to readableStream and upload this on IPFS. How can i convert that in typescript?

export async function putFileToIPFS(file:any): Promise<string>{
  readableStream = ** CONVERT FILE TO READABLE **
  let cid ;
  try {
  cid = await pinata.pinFileToIPFS(readableStream)
  console.log(cid)
  }   
  catch (error) { console.error(error);}
  return cid['IpfsHash']
}

Thanks

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

0

export async function putFileToIPFS(file: ArrayBuffer) {
  const readableStream = new ReadableBufferStream(file)
  ...
}

function ReadableBufferStream(ab: ArrayBuffer) {
  return new ReadableStream({
    start(controller) {
      controller.enqueue(ab)
      controller.close()
    }
  })
}

Alternatively, the "read size" could be controlled by setting a chunk size with multiple enqueues. This could potentially increase/decrease the number of HTTP requests sent by pinFileToIPFS(). subarray() maintains the memory footprint by reusing the underlying ArrayBuffer.

function ReadableBufferStream(ab: ArrayBuffer, chunkSize = 64*1024) { // 64 KiB
  return new ReadableStream({
    start(controller) {
      const bytes = new Uint8Array(ab)
      for (let readIndex = 0; readIndex < bytes.byteLength;) {
        controller.enqueue(bytes.subarray(readIndex, readIndex += chunkSize))
      }
      controller.close()
    }
  })
}
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