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

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

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