Skip to content

Commit 9cf442e

Browse files
committed
Strict null check zip
1 parent 3c2ed74 commit 9cf442e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@
479479
"./vs/platform/node/minimalTranslations.ts",
480480
"./vs/platform/node/package.ts",
481481
"./vs/platform/node/product.ts",
482+
"./vs/platform/node/zip.ts",
482483
"./vs/platform/notification/common/notification.ts",
483484
"./vs/platform/notification/test/common/testNotificationService.ts",
484485
"./vs/platform/opener/common/opener.ts",

src/vs/platform/node/zip.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export type ExtractErrorType = 'CorruptZip' | 'Incomplete';
3333

3434
export class ExtractError extends Error {
3535

36-
readonly type: ExtractErrorType;
36+
readonly type?: ExtractErrorType;
3737
readonly cause: Error;
3838

39-
constructor(type: ExtractErrorType, cause: Error) {
39+
constructor(type: ExtractErrorType | undefined, cause: Error) {
4040
let message = cause.message;
4141

4242
switch (type) {
@@ -62,7 +62,7 @@ function toExtractError(err: Error): ExtractError {
6262
return err;
6363
}
6464

65-
let type: ExtractErrorType = void 0;
65+
let type: ExtractErrorType | undefined = void 0;
6666

6767
if (/end of central directory record signature not found/.test(err.message)) {
6868
type = 'CorruptZip';
@@ -94,7 +94,7 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa
9494

9595
try {
9696
istream = createWriteStream(targetFileName, { mode });
97-
istream.once('close', () => c(null));
97+
istream.once('close', () => c());
9898
istream.once('error', e);
9999
stream.once('error', e);
100100
stream.pipe(istream);
@@ -105,7 +105,7 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa
105105
}
106106

107107
function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, logService: ILogService, token: CancellationToken): Promise<void> {
108-
let last = createCancelablePromise(() => Promise.resolve(null));
108+
let last = createCancelablePromise<void>(() => Promise.resolve());
109109
let extractedEntriesCount = 0;
110110

111111
once(token.onCancellationRequested)(() => {
@@ -129,7 +129,7 @@ function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, log
129129
zipfile.once('error', e);
130130
zipfile.once('close', () => last.then(() => {
131131
if (token.isCancellationRequested || zipfile.entryCount === extractedEntriesCount) {
132-
c(null);
132+
c();
133133
} else {
134134
e(new ExtractError('Incomplete', new Error(nls.localize('incompleteExtract', "Incomplete. Found {0} of {1} entries", extractedEntriesCount, zipfile.entryCount))));
135135
}
@@ -177,7 +177,13 @@ export interface IFile {
177177
export function zip(zipPath: string, files: IFile[]): Promise<string> {
178178
return new Promise<string>((c, e) => {
179179
const zip = new yazl.ZipFile();
180-
files.forEach(f => f.contents ? zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path) : zip.addFile(f.localPath, f.path));
180+
files.forEach(f => {
181+
if (f.contents) {
182+
zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path);
183+
} else if (f.localPath) {
184+
zip.addFile(f.localPath, f.path);
185+
}
186+
});
181187
zip.end();
182188

183189
const zipStream = createWriteStream(zipPath);

0 commit comments

Comments
 (0)