我正在使用nodejs后端,我需要获取用户正在上传的文件流列表的文件类型。每当我运行getStreamFileTypes
函数时,结果都是不正确的,我可能会得到图像的视频文件类型,反之亦然,并在控制台上显示以下错误:
(node:11868) MaxListnersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit
该如何解决?这是代码:
const getStreamFileTypes = async (streams) => {
try {
// get a list of detector promises
const typePromises = streams.map(stream => {
// pipe the stream content to detector
// to emit file type
miss.pipe(stream, detector, err => {
if(err) {
console.log('an error occured');
throw err;
}
});
// stream.pipe(detector).resume();
// return dector filetypepromise that resolves
// to the file type of the stream
return detector.fileTypePromise()
.then(filetype => {
return { ...filetype, stream };
})
.catch(error => {
throw UnknownError;
});
});
// wait for all stream's filetypes to be detected
const fileTypes = await Promise.all(typePromises);
return fileTypes;
} catch(error) {
console.log('error occured while getting stream types ', error);
throw error;
}
}