¿Cómo obtener el tipo MIME de 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) Puedo intentar tomar un tipo a través del header de mapeo tomado de la 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 }Pero quiero hacerlo más fácil.
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"}