最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - File type from buffer using file-type - Stack Overflow

programmeradmin2浏览0评论

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 0
Add a ment  | 

1 Answer 1

Reset to default 5

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

发布评论

评论列表(0)

  1. 暂无评论