Yuvraj Chavan
Yuvraj Chavan

Reputation: 65

File type from buffer using file-type

I tried finding type of file using file-type module but when i try to run it gives me error that "error:.... fileType.fromBuffer is not a function.

`

const fileType = require('file-type');
const readChunk = require('read-chunk');
exports.ext = async function(file) {
const buffer = readChunk.sync(file, 0, 512)
let type = await fileType.fromBuffer(buffer);
console.log("type of file",type)
return value

`

this is in utils.js file and i am calling it in other type.js file

`

var extension =  await utils.ext('ABC.png')
 console.log(extension)

`

Can anybody tell me what should i do?

Upvotes: 6

Views: 10313

Answers (1)

Risabh Sharma
Risabh Sharma

Reputation: 654

seems like there is a miss in npm documentation for the module file-type. The error which you are getting means the module doesn't expose such a method(fromBuffer).

Note that the function fromBuffer is now fileTypeFromBuffer in the latest version of the package.

the fileType accepts buffer as an input i.e.

await fileType.fileTypeFromBuffer(buffer)

kindly follow this file from the module source

Upvotes: 5

Related Questions