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?
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?
Share Improve this question asked Jan 11, 2020 at 7:38 Yuvraj ChavanYuvraj Chavan 651 gold badge1 silver badge6 bronze badges 01 Answer
Reset to default 5seems 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