Skip to content

Commit 994888e

Browse files
committed
move fileSources to libzip impl
1 parent e13fdd5 commit 994888e

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

.pnp.cjs

Lines changed: 12 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-libzip/sources/ZipFS.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ export class ZipFS extends BasePortableFakeFS {
109109
private readonly listings: Map<PortablePath, Set<Filename>> = new Map();
110110
private readonly entries: Map<PortablePath, number> = new Map();
111111

112-
/**
113-
* A cache of indices mapped to file sources.
114-
* Populated by `setFileSource` calls.
115-
* Required for supporting read after write.
116-
*/
117-
private readonly fileSources: Map<number, Buffer> = new Map();
118112

119113
private symlinkCount: number;
120114

@@ -742,8 +736,6 @@ export class ZipFS extends BasePortableFakeFS {
742736
if (typeof entry === `undefined`)
743737
return;
744738

745-
this.fileSources.delete(entry);
746-
747739
if (this.isSymbolicLink(entry)) {
748740
this.symlinkCount--;
749741
}
@@ -827,7 +819,6 @@ export class ZipFS extends BasePortableFakeFS {
827819
}
828820

829821
const newIndex = this.zipImpl.setFileSource(target, compression, buffer);
830-
this.fileSources.set(newIndex, buffer);
831822

832823
return newIndex;
833824
}
@@ -851,13 +842,8 @@ export class ZipFS extends BasePortableFakeFS {
851842
private getFileSource(index: number, opts: {asyncDecompress: true}): Promise<Buffer>;
852843
private getFileSource(index: number, opts: {asyncDecompress: boolean}): Promise<Buffer> | Buffer;
853844
private getFileSource(index: number, opts: {asyncDecompress: boolean} = {asyncDecompress: false}): Promise<Buffer> | Buffer {
854-
const cachedFileSource = this.fileSources.get(index);
855-
if (typeof cachedFileSource !== `undefined`)
856-
return cachedFileSource;
857-
858845
const {data, compressionMethod} = this.zipImpl.getFileSource(index);
859846
if (compressionMethod === STORE) {
860-
this.fileSources.set(index, data);
861847
return data;
862848
} else if (compressionMethod === DEFLATE) {
863849
if (opts.asyncDecompress) {
@@ -866,15 +852,12 @@ export class ZipFS extends BasePortableFakeFS {
866852
if (error) {
867853
reject(error);
868854
} else {
869-
this.fileSources.set(index, result);
870855
resolve(result);
871856
}
872857
});
873858
});
874859
} else {
875-
const decompressedData = zlib.inflateRawSync(data);
876-
this.fileSources.set(index, decompressedData);
877-
return decompressedData;
860+
return zlib.inflateRawSync(data);
878861
}
879862
} else {
880863
throw new Error(`Unsupported compression method: ${compressionMethod}`);

packages/yarnpkg-libzip/sources/libzipImpl.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export class LibZipImpl implements ZipImpl {
2121
private readonly lzSource: number;
2222
private readonly zip: number;
2323

24+
/**
25+
* A cache of indices mapped to file sources.
26+
* Populated by `setFileSource` calls.
27+
* Required for supporting read after write.
28+
*/
29+
private readonly fileSources: Map<number, Buffer> = new Map();
30+
2431
private readonly listings: Array<string>;
2532
private readonly symlinkCount: number;
2633

@@ -120,6 +127,7 @@ export class LibZipImpl implements ZipImpl {
120127
throw this.makeLibzipError(this.libzip.getError(this.zip));
121128
}
122129
}
130+
this.fileSources.set(newIndex, buffer);
123131
return newIndex;
124132
} catch (error) {
125133
this.libzip.source.free(lzSource);
@@ -156,6 +164,10 @@ export class LibZipImpl implements ZipImpl {
156164
}
157165

158166
getFileSource(index: number) {
167+
const cachedFileSource = this.fileSources.get(index);
168+
if (typeof cachedFileSource !== `undefined`)
169+
return {data: cachedFileSource, compressionMethod: 0};
170+
159171
const stat = this.libzip.struct.statS();
160172

161173
const rc = this.libzip.statIndex(this.zip, index, 0, 0, stat);
@@ -194,6 +206,7 @@ export class LibZipImpl implements ZipImpl {
194206
}
195207

196208
deleteEntry(index: number) {
209+
this.fileSources.delete(index);
197210
const rc = this.libzip.delete(this.zip, index);
198211
if (rc === -1) {
199212
throw this.makeLibzipError(this.libzip.getError(this.zip));

packages/yarnpkg-pnp/sources/hook.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)