Detecting file type from buffer in node js?
问题 I have created a buffer from a file which can be pdf, jpg or any other format. Now I want to detect if the buffer is of the pdf file or any other file. request({ url, encoding: null }, (err, resp, buffer) => { hashFromFilebuffer('sha256', buffer).then(function (result) { console.log(result) }).catch(function (error) { console.log(error) }); }); 回答1: Have a look at this: https://github.com/sindresorhus/file-type/ . If you want to know how it works, I think the code is at https://github.com