I’m using the following code (courtesy of D.Dimitrioglo) to compress a directory to a zip file.
/**
* @param {String} sourceDir: /some/folder/to/compress
* @param {String} outPath: /path/to/created.zip
* @returns {Promise}
*/
export function zipDirectory(sourceDir: string, outPath: string) {
const archive = archiver('zip', {zlib: {level: 9}});
const stream = fs.createWriteStream(outPath);
return new Promise((resolve, reject) => {
archive
.directory(sourceDir, false)
.on('error', (err: any) => reject(err))
.pipe(stream)
;
stream.on('error', ex => reject(ex));
stream.on('warning', ex => console.log(ex));
stream.on('close', () => resolve(undefined));
archive.finalize();
});
}
I have an express typescript server that runs the zipDirectory function. However, when running the function, I get the following warnings:
(node:3275) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [ReadStream]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3275) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [ReadStream]. Use emitter.setMaxListeners() to increase limit
I used –trace-warnings to further inspect the warning:
(node:5327) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [ReadStream]. Use emitter.setMaxListeners() to increase limit
at _addListener (node:events:465:17)
at ReadStream.addListener (node:events:487:10)
at ReadStream.Readable.on (node:internal/streams/readable:876:35)
at ReadStream.once (node:events:531:8)
at ReadStream.Readable.pipe (node:internal/streams/readable:678:9)
at gm._spawn (/home/user/workspace/tools/backend/node_modules/gm/lib/command.js:262:25)
at /home/alqio/workspace/tools/backend/node_modules/gm/lib/command.js:101:12
at series (/home/user/workspace/tools/backend/node_modules/array-series/index.js:11:36)
at gm._preprocess (/home/user/workspace/tools/backend/node_modules/gm/lib/command.js:177:5)
at gm.write (/home/user/workspace/tools/backend/node_modules/gm/lib/command.js:99:10)
(node:5327) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [ReadStream]. Use emitter.setMaxListeners() to increase limit
at _addListener (node:events:465:17)
at ReadStream.addListener (node:events:487:10)
at ReadStream.Readable.on (node:internal/streams/readable:876:35)
at ReadStream.Readable.pipe (node:internal/streams/readable:751:7)
at gm._spawn (/home/user/workspace/tools/backend/node_modules/gm/lib/command.js:262:25)
at /home/user/workspace/tools/backend/node_modules/gm/lib/command.js:101:12
at series (/home/user/workspace/tools/backend/node_modules/array-series/index.js:11:36)
at gm._preprocess (/home/user/workspace/tools/backend/node_modules/gm/lib/command.js:177:5)
at gm.write (/home/user/workspace/tools/backend/node_modules/gm/lib/command.js:99:10)
at /home/user/workspace/tools/backend/node_modules/pdf2pic/dist/index.js:1:1360
The code works, but what is the reason for these warnings?