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

188
Vistas
How to get MIME type from Unit8Array?

How to get MIME type from Unit8Array?

import all from 'it-all'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'

const hash = 'QmRW5tvGURXTcWwch5hQyeaEVdmeU3RGjyBo8cLZhmhS9x'
const response = uint8ArrayConcat(await all(ipfs.cat(hash)))

console.log('response', response)
> Uint8Array(6746687)

I can try to take a type through the mapping header taken from response:

switch (header) {
    case '89504e47':
      type = 'image/png';
      break;
    case '47494638':
      type = 'image/gif'
      break
    case 'ffd8ffe0':
    case 'ffd8ffe1':
    case 'ffd8ffe2':
    case 'ffd8ffe3':
    case 'ffd8ffe8':
      type = 'image/jpeg'
      break
    default:
      type = 'unknown'
      break
}

But I want to do it easier.

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

0

import fileType from 'file-type'
import all from 'it-all'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'

const hash = 'QmRW5tvGURXTcWwch5hQyeaEVdmeU3RGjyBo8cLZhmhS9x'
const response = uint8ArrayConcat(await all(ipfs.cat(hash)))
const {ext, mime} = await fileType.fromBuffer(response)

> {ext: "mp3", mime: "audio/mpeg"}
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