1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import * as fs from 'fs';
|
10 | import * as stream from 'stream';
|
11 | import * as ReaddirGlob from 'readdir-glob';
|
12 | import { ZlibOptions } from 'zlib';
|
13 |
|
14 | type Partial<T> = {
|
15 | [P in keyof T]?: T[P];
|
16 | };
|
17 |
|
18 |
|
19 | type GlobOptions = ReaddirGlob.Options & { cwd?: string };
|
20 |
|
21 |
|
22 | type ConstructorFn<T> = Function | (new (...params: any[]) => T);
|
23 |
|
24 | declare function archiver(format: archiver.Format, options?: archiver.ArchiverOptions): archiver.Archiver;
|
25 |
|
26 | declare namespace archiver {
|
27 | type Format = 'zip' | 'tar';
|
28 |
|
29 | function create(format: string, options?: ArchiverOptions): Archiver;
|
30 |
|
31 | /** Check if the format is already registered. */
|
32 | function isRegisteredFormat(format: string): boolean;
|
33 | // tslint:disable-next-line:ban-types Function
|
34 | function registerFormat(format: string, module: Function): void;
|
35 |
|
36 | interface EntryData {
|
37 | /** Sets the entry name including internal path */
|
38 | name: string;
|
39 | /** Sets the entry date */
|
40 | date?: Date | string | undefined;
|
41 | /** Sets the entry permissions */
|
42 | mode?: number | undefined;
|
43 | /**
|
44 | * Sets a path prefix for the entry name.
|
45 | * Useful when working with methods like `directory` or `glob`
|
46 | */
|
47 | prefix?: string | undefined;
|
48 | /**
|
49 | * Sets the fs stat data for this entry allowing
|
50 | * for reduction of fs stat calls when stat data is already known
|
51 | */
|
52 | stats?: fs.Stats | undefined;
|
53 | }
|
54 |
|
55 | interface ZipEntryData extends EntryData {
|
56 | /** Sets the compression method to STORE */
|
57 | store?: boolean | undefined;
|
58 | }
|
59 |
|
60 | type TarEntryData = EntryData;
|
61 |
|
62 | interface ProgressData {
|
63 | entries: {
|
64 | total: number;
|
65 | processed: number;
|
66 | };
|
67 | fs: {
|
68 | totalBytes: number;
|
69 | processedBytes: number;
|
70 | };
|
71 | }
|
72 |
|
73 | /** A function that lets you either opt out of including an entry (by returning false), or modify the contents of an entry as it is added (by returning an EntryData) */
|
74 | type EntryDataFunction = (entry: EntryData) => false | EntryData;
|
75 |
|
76 | class ArchiverError extends Error {
|
77 | code: string;
|
78 | data: any;
|
79 | path?: any;
|
80 |
|
81 | constructor(code: string, data: any);
|
82 | }
|
83 |
|
84 | interface Archiver extends stream.Transform {
|
85 | abort(): this;
|
86 | append(source: stream.Readable | Buffer | string, data?: EntryData | ZipEntryData | TarEntryData): this;
|
87 |
|
88 |
|
89 | directory(dirpath: string, destpath: false | string, data?: Partial<EntryData> | EntryDataFunction): this;
|
90 | file(filename: string, data: EntryData): this;
|
91 | glob(pattern: string, options?: GlobOptions, data?: Partial<EntryData>): this;
|
92 | finalize(): Promise<void>;
|
93 |
|
94 | setFormat(format: string): this;
|
95 |
|
96 | setModule(module: Function): this;
|
97 |
|
98 | pointer(): number;
|
99 | // tslint:disable-next-line:ban-types Function
|
100 | use(plugin: Function): this;
|
101 |
|
102 | symlink(filepath: string, target: string, mode?: number): this;
|
103 |
|
104 | on(event: 'error' | 'warning', listener: (error: ArchiverError) => void): this;
|
105 | on(event: 'data', listener: (data: Buffer) => void): this;
|
106 | on(event: 'progress', listener: (progress: ProgressData) => void): this;
|
107 | on(event: 'close' | 'drain' | 'finish', listener: () => void): this;
|
108 | on(event: 'pipe' | 'unpipe', listener: (src: stream.Readable) => void): this;
|
109 | on(event: 'entry', listener: (entry: EntryData) => void): this;
|
110 | on(event: string, listener: (...args: any[]) => void): this;
|
111 | }
|
112 |
|
113 | type ArchiverOptions = CoreOptions & TransformOptions & ZipOptions & TarOptions;
|
114 |
|
115 | interface CoreOptions {
|
116 | statConcurrency?: number | undefined;
|
117 | }
|
118 |
|
119 | interface TransformOptions {
|
120 | allowHalfOpen?: boolean | undefined;
|
121 | readableObjectMode?: boolean | undefined;
|
122 | writeableObjectMode?: boolean | undefined;
|
123 | decodeStrings?: boolean | undefined;
|
124 | encoding?: string | undefined;
|
125 | highWaterMark?: number | undefined;
|
126 | objectmode?: boolean | undefined;
|
127 | }
|
128 |
|
129 | interface ZipOptions {
|
130 | comment?: string | undefined;
|
131 | forceLocalTime?: boolean | undefined;
|
132 | forceZip64?: boolean | undefined;
|
133 |
|
134 | namePrependSlash?: boolean | undefined;
|
135 | store?: boolean | undefined;
|
136 | zlib?: ZlibOptions | undefined;
|
137 | }
|
138 |
|
139 | interface TarOptions {
|
140 | gzip?: boolean | undefined;
|
141 | gzipOptions?: ZlibOptions | undefined;
|
142 | }
|
143 | }
|
144 |
|
145 | export = archiver;
|