Skip to content

Commit

Permalink
Fix entry duplication and empty entries
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Oct 9, 2024
1 parent b92ff20 commit 0d9041a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ZipFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface ZipOptions {
*/
export class ZipFS extends Readonly(Sync(FileSystem)) {
protected files: Map<string, FileEntry> = new Map();
protected directories: Map<string, string[]> = new Map();
protected directories: Map<string, Set<string>> = new Map();

protected _time = Date.now();

Expand Down Expand Up @@ -134,21 +134,23 @@ export class ZipFS extends Readonly(Sync(FileSystem)) {
const { dir, base } = parse(entry);

if (!this.directories.has(dir)) {
this.directories.set(dir, []);
this.directories.set(dir, new Set());
}

this.directories.get(dir)!.push(base);
this.directories.get(dir)!.add(base);
}

// Add subdirectories to their parent's entries
for (const entry of this.directories.keys()) {
const { dir, base } = parse(entry);

if (base == '') continue;

if (!this.directories.has(dir)) {
this.directories.set(dir, []);
this.directories.set(dir, new Set());
}

this.directories.get(dir)!.push(base);
this.directories.get(dir)!.add(base);
}
}

Expand Down Expand Up @@ -211,7 +213,7 @@ export class ZipFS extends Readonly(Sync(FileSystem)) {
throw ErrnoError.With('ENODATA', path, 'readdir');
}

return entries;
return Array.from(entries);
}
}

Expand Down

0 comments on commit 0d9041a

Please sign in to comment.