Is it necessary to close the object? I want to keep more than one zip file open, but, at some point, I’ll have finished with one or the other. I’ve wrapped the opening process in a simple function:
const unzipper = require('unzipper');
const path = require("path")
async function openZip(zipFile) {
let directory = {};
let zip = await unzipper.Open.file(zipFile);
let root = zip.files[0].path.replace(/\/$/,'');
zip.files.forEach(f => {
let path = f.path;
if(path.split('/').pop().charAt(0) != '.') directory[path] = f;
});
return { zip, directory };
}
async function doit() {
let { zip1, directory1 } = await openZip(…);
let { zip2, directory2 } = await openZip(…);
// do things …
// dispose of objects … ?
// do more things
}
Here the function returns a reference to the unzipper object, as well as a simplified directory.
Once I’ve finished with the unzipper object, how would I dispose of it? There doesn’t appear to be a .close() method.
BTW, I’m making a few wild assumptions here:
- The root directory is item 0
- That my
directory object code is the simplest way of extracting the directory.
I’m happy to be corrected on these assumptions.
Is it necessary to close the object? I want to keep more than one zip file open, but, at some point, I’ll have finished with one or the other. I’ve wrapped the opening process in a simple function:
Here the function returns a reference to the unzipper object, as well as a simplified directory.
Once I’ve finished with the unzipper object, how would I dispose of it? There doesn’t appear to be a
.close()method.BTW, I’m making a few wild assumptions here:
directoryobject code is the simplest way of extracting the directory.I’m happy to be corrected on these assumptions.