UNPKG

5.3 kBTypeScriptView Raw
1// Type definitions for tar v1.0.1
2// Project: https://github.com/npm/node-tar
3// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TODO: When/if typings for [fstream](https://github.com/npm/fstream) are written, refactor this typing to use it for the various streams.
6
7/// <reference types="node" />
8
9
10import stream = require("stream");
11
12// #region Interfaces
13
14export interface HeaderProperties {
15 path?: string;
16 mode?: number;
17 uid?: number;
18 gid?: number;
19 size?: number;
20 mtime?: number;
21 uname?: string;
22 gname?: string;
23 devmaj?: number;
24 devmin?: number;
25}
26
27export interface ExtractOptions {
28 type?: string;
29 Directory?: boolean;
30 path?: string;
31 strip?: number;
32}
33
34export interface ParseStream extends NodeJS.ReadWriteStream {
35 position: number;
36
37 _stream: stream.Stream;
38 _ended: boolean;
39
40 _streamEnd(): void;
41 _process(c: Buffer): void;
42 _startEntry(c: Buffer): void;
43}
44
45export interface PackStream extends NodeJS.ReadWriteStream {
46 writable: boolean;
47 readable: boolean;
48
49 _noProprietary: boolean;
50 _global: HeaderProperties;
51 _buffer: stream.Stream[];
52 _currentEntry: any;
53 _processing: boolean;
54 _pipeRoot: stream.Stream;
55 _needDrain: boolean;
56 _paused: boolean;
57
58 addGlobal(props: HeaderProperties): void;
59 add(stream: stream.Stream): boolean;
60 destroy(): void;
61
62 _process(): void;
63}
64
65export interface ExtractStream extends ParseStream {
66}
67
68// #endregion
69
70// #region Enums
71
72export declare var fields: {
73 path: number;
74 mode: number;
75 uid: number;
76 gid: number;
77 size: number;
78 mtime: number;
79 cksum: number;
80 type: number;
81 linkpath: number;
82 ustar: number;
83 ustarvar: number;
84 uname: number;
85 gname: number;
86 devmaj: number;
87 devmin: number;
88 prefix: number;
89 fill: number;
90};
91
92export declare var fieldSize: number[];
93export declare var fieldOffs: number[];
94export declare var fieldEnds: number[];
95
96/**
97 * Different values of the 'type' field
98 * paths match the values of Stats.isX() functions, where appropriate
99 */
100export declare var types: {
101 0: string;
102 "\0": string;
103 "": string;
104 1: string;
105 2: string;
106 3: string;
107 4: string;
108 5: string;
109 6: string;
110 7: string;
111 g: string;
112 x: string;
113 A: string;
114 D: string;
115 I: string;
116 K: string;
117 L: string;
118 M: string;
119 N: string;
120 S: string;
121 V: string;
122 X: string;
123 File: string;
124 OldFile: string;
125 Link: string;
126 SymbolicLick: string;
127 CharacterDevice: string;
128 BlockDevice: string;
129 Directory: string;
130 FIFO: string;
131 ContiguousFile: string;
132 GlobalExtendedHeader: string;
133 ExtendedHeader: string;
134 SolarisACL: string;
135 GNUDumpDir: string;
136 INode: string;
137 NextFileHasLonLinkPath: string;
138 NextFileHasLongPath: string;
139 ContinuationFile: string;
140 TapeVolumeHeader: string;
141 OldExtendedHeader: string;
142};
143
144/**
145 * Values for the mode field
146 */
147export declare var modes: {
148 suid: number;
149 sgid: number;
150 svtx: number;
151 uread: number;
152 uwrite: number;
153 uexec: number;
154 gread: number;
155 gwrite: number;
156 gexec: number;
157 oread: number;
158 owrite: number;
159 oexec: number;
160};
161
162export declare var numeric: {
163 mode: boolean;
164 uid: boolean;
165 gid: boolean;
166 size: boolean;
167 mtime: boolean;
168 devmaj: boolean;
169 devmin: boolean;
170 cksum: boolean;
171 atime: boolean;
172 ctime: boolean;
173 dev: boolean;
174 ino: boolean;
175 nlink: boolean;
176};
177
178export declare var knownExtended: {
179 atime: boolean;
180 charset: boolean;
181 comment: boolean;
182 ctime: boolean;
183 gid: boolean;
184 gname: boolean;
185 linkpat: boolean;
186 mtime: boolean;
187 path: boolean;
188 realtime: boolean;
189 security: boolean;
190 size: boolean;
191 uid: boolean;
192 uname: boolean;
193};
194
195export declare var headerSize: number;
196export declare var blockSize: number;
197
198//#endregion
199
200//#region Global Methods
201
202/**
203 * Returns a writable stream. Write tar data to it and it will emit entry events for each entry parsed from the tarball. This is used by tar.Extract.
204 */
205export declare function Parse(): ParseStream;
206/**
207 * Returns a through stream. Use fstream to write files into the pack stream and you will receive tar archive data from the pack stream.
208 * This only works with directories, it does not work with individual files.
209 * The optional properties object are used to set properties in the tar 'Global Extended Header'.
210 */
211export declare function Pack(props?: HeaderProperties): PackStream;
212/**
213 * Returns a through stream. Write tar data to the stream and the files in the tarball will be extracted onto the filesystem.
214 */
215export declare function Extract(path: string): ExtractStream;
216/**
217 * Returns a through stream. Write tar data to the stream and the files in the tarball will be extracted onto the filesystem.
218 * options can be:
219 * ```
220 * {
221 * path: '/path/to/extract/tar/into',
222 * strip: 0, // how many path segments to strip from the root when extracting
223 * }
224 * ```
225 * options also get passed to the fstream.Writer instance that tar uses internally.
226 */
227export declare function Extract(opts: ExtractOptions): ExtractStream;