104
}
105
106
>
function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, token: CancellationToken): Promise<void> {
zip.ts
107
>
let last = createCancelablePromise<void>(() => Promise.resolve());
108
>
let extractedEntriesCount = 0;
109
>
110
>
const listener = token.onCancellationRequested(() => {
111
last.cancel();
112
zipfile.close();
114
>
115
>
return new Promise<void>((c, e) => {
116
>
const throttler = new Sequencer();
117
>
118
>
const readNextEntry = (token: CancellationToken) => {
119
>
if (token.isCancellationRequested) {
120
return;
121
}
123
>
extractedEntriesCount++;
124
>
zipfile.readEntry();
125
>
};
126
>
127
>
zipfile.once('error', e);
128
>
zipfile.once('close', () => last.then(() => {
129
>
if (token.isCancellationRequested || zipfile.entryCount === extractedEntriesCount) {
130
>
c();
131
>
} else {
132
e(new ExtractError('Incomplete', new Error(nls.localize('incompleteExtract', "Incomplete. Found {0} of {1} entries", extractedEntriesCount, zipfile.entryCount))));
133
}
135
>
zipfile.readEntry();
136
>
zipfile.on('entry', (entry: Entry) => {
137
>
138
>
if (token.isCancellationRequested) {
139
return;
140
}
142
>
if (!options.sourcePathRegex.test(entry.fileName)) {
143
readNextEntry(token);
144
return;
145
}
147
>
const fileName = entry.fileName.replace(options.sourcePathRegex, '');
148
>
149
>
// directory file names end with '/'
150
>
if (/\/$/.test(fileName)) {
151
>
const targetFileName = path.join(targetPath, fileName);
152
>
last = createCancelablePromise(token => promises.mkdir(targetFileName, { recursive: true }).then(() => readNextEntry(token)).then(undefined, e));
153
>
return;
154
>
}
155
156
const stream = openZipStream(zipfile, entry);