Support ZIP files without directory entries

This commit is contained in:
Mattias Frinnström
2020-11-18 16:28:27 +01:00
parent b1b6537bc3
commit 3092806838
2 changed files with 8 additions and 5 deletions
@@ -136,13 +136,16 @@ export class ZipArchiveResponse implements ReadTreeResponse {
if (this.shouldBeIncluded(entry)) {
const entryPath = this.getPath(entry);
if (entry.type === 'Directory') {
if (entryPath) {
fs.mkdirSync(path.join(dir, entryPath));
}
// Ignore directory entries since we handle that with the file entries
// since a zip can have files with directories without directory entries
entry.resume();
} else {
entry.pipe(fs.createWriteStream(path.join(dir, entryPath)));
return;
}
const dirname = path.dirname(entryPath);
if (dirname) {
fs.mkdirSync(path.join(dir, dirname), { recursive: true });
}
entry.pipe(fs.createWriteStream(path.join(dir, entryPath)));
} else {
entry.autodrain();
}