222
schangxiang@126.com
2025-06-13 6a8393408d8cefcea02b7a598967de8dc1e565c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Type definitions for archiver 3.1
// Project: https://github.com/archiverjs/node-archiver
// Definitions by:  Esri <https://github.com/archiverjs/node-archiver>
//                  Dolan Miu <https://github.com/dolanmiu>
//                  Crevil <https://github.com/crevil>
//                  Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
 
import * as fs from 'fs';
import * as stream from 'stream';
import * as glob from 'glob';
import { ZlibOptions } from 'zlib';
 
type Partial<T> = {
    [P in keyof T]?: T[P];
};
 
declare function archiver(format: archiver.Format, options?: archiver.ArchiverOptions): archiver.Archiver;
 
declare namespace archiver {
    type Format = 'zip' | 'tar';
 
    function create(format: string, options?: ArchiverOptions): Archiver;
    function registerFormat(format: string, module: Function): void;
 
    interface EntryData {
        /** Sets the entry name including internal path */
        name: string;
        /** Sets the entry date */
        date?: Date | string;
        /** Sets the entry permissions */
        mode?: number;
        /**
         * Sets a path prefix for the entry name.
         * Useful when working with methods like `directory` or `glob`
         */
        prefix?: string;
        /**
         * Sets the fs stat data for this entry allowing
         * for reduction of fs stat calls when stat data is already known
         */
        stats?: fs.Stats;
    }
 
    interface ZipEntryData extends EntryData {
        /** Sets the compression method to STORE */
        store?: boolean;
    }
 
    type TarEntryData = EntryData;
 
    interface ProgressData {
        entries: {
            total: number;
            processed: number;
        };
        fs: {
            totalBytes: number;
            processedBytes: number;
        };
    }
 
    /** 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) */
    type EntryDataFunction = (entry: EntryData) => false | EntryData;
 
    class ArchiverError extends Error {
        code: string; // Since archiver format support is modular, we cannot enumerate all possible error codes, as the modules can throw arbitrary ones.
        data: any;
        path?: any;
 
        constructor(code: string, data: any);
    }
 
    interface Archiver extends stream.Transform {
        abort(): this;
        append(source: stream.Readable | Buffer | string, data?: EntryData | ZipEntryData | TarEntryData): this;
 
        /** if false is passed for destpath, the path of a chunk of data in the archive is set to the root */
        directory(dirpath: string, destpath: false | string, data?: Partial<EntryData> | EntryDataFunction): this;
        file(filename: string, data: EntryData): this;
        glob(pattern: string, options?: glob.IOptions, data?: Partial<EntryData>): this;
        finalize(): Promise<void>;
 
        setFormat(format: string): this;
        setModule(module: Function): this;
 
        pointer(): number;
        use(plugin: Function): this;
 
        symlink(filepath: string, target: string): this;
 
        on(event: 'error' | 'warning', listener: (error: ArchiverError) => void): this;
        on(event: 'data', listener: (data: EntryData) => void): this;
        on(event: 'progress', listener: (progress: ProgressData) => void): this;
        on(event: 'close' | 'drain' | 'finish', listener: () => void): this;
        on(event: 'pipe' | 'unpipe', listener: (src: stream.Readable) => void): this;
        on(event: 'entry', listener: (entry: EntryData) => void): this;
        on(event: string, listener: (...args: any[]) => void): this;
    }
 
    type ArchiverOptions = CoreOptions & TransformOptions & ZipOptions & TarOptions;
 
    interface CoreOptions {
        statConcurrency?: number;
    }
 
    interface TransformOptions {
        allowHalfOpen?: boolean;
        readableObjectMode?: boolean;
        writeableObjectMode?: boolean;
        decodeStrings?: boolean;
        encoding?: string;
        highWaterMark?: number;
        objectmode?: boolean;
    }
 
    interface ZipOptions {
        comment?: string;
        forceLocalTime?: boolean;
        forceZip64?: boolean;
        store?: boolean;
        zlib?: ZlibOptions;
    }
 
    interface TarOptions {
        gzip?: boolean;
        gzipOptions?: ZlibOptions;
    }
}
 
export = archiver;