Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
179
rated 0 times [  183] [ 4]  / answers: 1 / hits: 6058  / 4 Years ago, sat, january 11, 2020, 12:00:00

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?


More From » node.js

 Answers
0

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).



the fileType accepts buffer as an input i.e.
replace



await fileType.fromBuffer(buffer)


with



await fileType(buffer)


kindly follow this file from the module source


[#5080] Thursday, January 9, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frederickmohamedw

Total Points: 21
Total Questions: 123
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
frederickmohamedw questions
Wed, Sep 23, 20, 00:00, 4 Years ago
Sat, Jul 18, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Fri, Dec 27, 19, 00:00, 5 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;