I am using the file-type
package (https://www.npmjs.com/package/file-type) to determine the mime type of a file from a buffer. The function returns a promise, and I would like to extract only the mime like this application/dicom
.
const mimeType = await FileType.fromBuffer(buffer);
console.log(mimeType); // { ext: 'dcm', mime: 'application/dicom' }
Is something like this possible?
const { ext, mime } = await FileType.fromBuffer(buffer);
console.log(ext);
console.log(mime);
You can either do
const { ext, mime } = await FileType.fromBuffer(buffer) || { mine: 'unknown', ext: 'unknown' }
or probably even just
const { ext, mime } = await FileType.fromBuffer(buffer) as FileTypeResult