1
>
/*---------------------------------------------------------------------------------------------
zip.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { createWriteStream, WriteStream, promises } from 'fs';
7
>
import type { FileHandle } from 'fs/promises';
8
>
import { Readable } from 'stream';
9
>
import { createCancelablePromise, Sequencer } from '../common/async.js';
10
>
import { CancellationToken } from '../common/cancellation.js';
11
>
import * as path from '../common/path.js';
12
>
import { assertReturnsDefined } from '../common/types.js';
13
>
import { Promises } from './pfs.js';
14
>
import * as nls from '../../nls.js';
15
>
import type { Entry, ZipFile } from 'yauzl';
16
>
17
>
export const CorruptZipMessage: string = 'end of central directory record signature not found';
18
>
const CORRUPT_ZIP_PATTERN = new RegExp(CorruptZipMessage);
19
>
20
>
export interface IExtractOptions {
21
>
overwrite?: boolean;
22
>
23
>
/**
24
>
* Source path within the ZIP archive. Only the files contained in this
25
>
* path will be extracted.
26
>
*/
27
>
sourcePath?: string;
28
>
}
29
>
30
>
interface IOptions {
31
>
sourcePathRegex: RegExp;
32
>
}
33
>
34
>
export type ExtractErrorType = 'CorruptZip' | 'Incomplete';
35
>
36
>
export class ExtractError extends Error {
37
>
38
>
readonly type?: ExtractErrorType;
39
>
40
>
constructor(type: ExtractErrorType | undefined, cause: Error) {
41
let message = cause.message;
42