@@ -4,207 +4,202 @@ import path from 'node:path';
44/**
55 * Create a tar archive from a directory.
66 */
7- export async function createTar ( sourceFile : string , destinationFile : string ) : Promise < void > {
8- return new Promise ( async ( resolve , reject ) => {
9- destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
10-
11- const proc = spawn (
12- 'tar' ,
13- [ '-cvf' , destinationFile , sourceFile ]
14- ) ;
15-
16- proc . on ( 'exit' , ( code ) => {
17- if ( code !== 0 ) {
18- reject ( new Error ( `Failed to create tar archive. Exit code: ${ code } ` ) ) ;
19- }
20- resolve ( undefined ) ;
21- } ) ;
7+ export async function createTar (
8+ sourceFile : string ,
9+ destinationFile : string ,
10+ ) : Promise < void > {
11+ return new Promise ( async ( resolve , reject ) => {
12+ destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
13+
14+ const proc = spawn ( 'tar' , [ '-cvf' , destinationFile , sourceFile ] ) ;
15+
16+ proc . on ( 'exit' , ( code ) => {
17+ if ( code !== 0 ) {
18+ reject ( new Error ( `Failed to create tar archive. Exit code: ${ code } ` ) ) ;
19+ }
20+ resolve ( undefined ) ;
2221 } ) ;
22+ } ) ;
2323}
2424
2525/**
2626 * Extract the contents of a tar archive.
2727 */
2828export async function extractTar ( sourceFile : string ) : Promise < void > {
29- return new Promise ( async ( resolve , reject ) => {
30- const proc = spawn (
31- 'tar' ,
32- [ '-xvf' , sourceFile ]
33- ) ;
34-
35- proc . on ( 'exit' , ( code ) => {
36- if ( code !== 0 ) {
37- reject ( new Error ( `Failed to extract tar archive. Exit code: ${ code } ` ) ) ;
38- }
39- resolve ( undefined ) ;
40- } ) ;
29+ return new Promise ( async ( resolve , reject ) => {
30+ const proc = spawn ( 'tar' , [ '-xvf' , sourceFile ] ) ;
31+
32+ proc . on ( 'exit' , ( code ) => {
33+ if ( code !== 0 ) {
34+ reject ( new Error ( `Failed to extract tar archive. Exit code: ${ code } ` ) ) ;
35+ }
36+ resolve ( undefined ) ;
4137 } ) ;
38+ } ) ;
4239}
4340
4441/**
4542 * Create a gzip archive from a directory.
4643 */
47- export async function createGzip ( sourceFile : string , destinationFile : string ) : Promise < void > {
48- return new Promise ( async ( resolve , reject ) => {
49- destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
50-
51- const proc = spawn (
52- 'tar' ,
53- [ '-czvf' , destinationFile , sourceFile ]
54- ) ;
55-
56- proc . on ( 'exit' , ( code ) => {
57- if ( code !== 0 ) {
58- reject ( new Error ( `Failed to create gzip archive. Exit code: ${ code } ` ) ) ;
59- }
60- resolve ( undefined ) ;
61- } ) ;
44+ export async function createGzip (
45+ sourceFile : string ,
46+ destinationFile : string ,
47+ ) : Promise < void > {
48+ return new Promise ( async ( resolve , reject ) => {
49+ destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
50+
51+ const proc = spawn ( 'tar' , [ '-czvf' , destinationFile , sourceFile ] ) ;
52+
53+ proc . on ( 'exit' , ( code ) => {
54+ if ( code !== 0 ) {
55+ reject ( new Error ( `Failed to create gzip archive. Exit code: ${ code } ` ) ) ;
56+ }
57+ resolve ( undefined ) ;
6258 } ) ;
59+ } ) ;
6360}
6461
6562/**
6663 * Extract the contents of a gzip archive.
6764 */
6865export async function extractGzip ( sourceFile : string ) : Promise < void > {
69- return new Promise ( async ( resolve , reject ) => {
70- const proc = spawn (
71- 'tar' ,
72- [ '-xzvf' , sourceFile ]
73- ) ;
74-
75- proc . on ( 'exit' , ( code ) => {
76- if ( code !== 0 ) {
77- reject ( new Error ( `Failed to extract gzip archive. Exit code: ${ code } ` ) ) ;
78- }
79- resolve ( undefined ) ;
80- } ) ;
66+ return new Promise ( async ( resolve , reject ) => {
67+ const proc = spawn ( 'tar' , [ '-xzvf' , sourceFile ] ) ;
68+
69+ proc . on ( 'exit' , ( code ) => {
70+ if ( code !== 0 ) {
71+ reject ( new Error ( `Failed to extract gzip archive. Exit code: ${ code } ` ) ) ;
72+ }
73+ resolve ( undefined ) ;
8174 } ) ;
75+ } ) ;
8276}
8377
8478/**
8579 * Create a bzip2 archive from a directory.
8680 */
87- export async function createBzip2 ( sourceFile : string , destinationFile : string ) : Promise < void > {
88- return new Promise ( async ( resolve , reject ) => {
89- destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
90-
91- const proc = spawn (
92- 'tar' ,
93- [ '-cjvf' , destinationFile , sourceFile ]
94- ) ;
95-
96- proc . on ( 'exit' , ( code ) => {
97- if ( code !== 0 ) {
98- reject ( new Error ( `Failed to create bzip2 archive. Exit code: ${ code } ` ) ) ;
99- }
100- resolve ( undefined ) ;
101- } ) ;
81+ export async function createBzip2 (
82+ sourceFile : string ,
83+ destinationFile : string ,
84+ ) : Promise < void > {
85+ return new Promise ( async ( resolve , reject ) => {
86+ destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
87+
88+ const proc = spawn ( 'tar' , [ '-cjvf' , destinationFile , sourceFile ] ) ;
89+
90+ proc . on ( 'exit' , ( code ) => {
91+ if ( code !== 0 ) {
92+ reject ( new Error ( `Failed to create bzip2 archive. Exit code: ${ code } ` ) ) ;
93+ }
94+ resolve ( undefined ) ;
10295 } ) ;
96+ } ) ;
10397}
10498
10599/**
106100 * Extract the contents of a bzip2 archive.
107101 */
108102export async function extractBzip2 ( sourceFile : string ) : Promise < void > {
109- return new Promise ( async ( resolve , reject ) => {
110- const proc = spawn (
111- 'tar' ,
112- [ '-xjvf' , sourceFile ]
113- ) ;
103+ return new Promise ( async ( resolve , reject ) => {
104+ const proc = spawn ( 'tar' , [ '-xjvf' , sourceFile ] ) ;
114105
115- proc . on ( 'exit' , ( code ) => {
116- if ( code !== 0 ) {
117- reject (
118- new Error ( `Failed to extract bzip2 archive. Exit code: ${ code } ` ) ,
119- ) ;
120- }
121- resolve ( undefined ) ;
122- } ) ;
106+ proc . on ( 'exit' , ( code ) => {
107+ if ( code !== 0 ) {
108+ reject (
109+ new Error ( `Failed to extract bzip2 archive. Exit code: ${ code } ` ) ,
110+ ) ;
111+ }
112+ resolve ( undefined ) ;
123113 } ) ;
114+ } ) ;
124115}
125116
126117/**
127118 * Create a rar archive from a directory recursively.
128119 */
129- export async function createRar ( sourceFile : string , destinationFile : string ) : Promise < void > {
130- return new Promise ( async ( resolve , reject ) => {
131- destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
132-
133- const proc = spawn (
134- 'rar' ,
135- [ 'a' , '-r' , destinationFile , sourceFile ]
120+ export async function createRar (
121+ sourceFile : string ,
122+ destinationFile : string ,
123+ ) : Promise < void > {
124+ return new Promise ( async ( resolve , reject ) => {
125+ destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
126+
127+ const proc = spawn ( 'rar' , [ 'a' , '-r' , destinationFile , sourceFile ] ) ;
128+
129+ proc . on ( 'exit' , ( code ) => {
130+ if ( code !== 0 ) {
131+ reject (
132+ new Error (
133+ `Failed to create rar archive from directory. Exit code: ${ code } ` ,
134+ ) ,
136135 ) ;
137-
138- proc . on ( 'exit' , ( code ) => {
139- if ( code !== 0 ) {
140- reject (
141- new Error (
142- `Failed to create rar archive from directory. Exit code: ${ code } ` ,
143- ) ,
144- ) ;
145- }
146- resolve ( undefined ) ;
147- } ) ;
136+ }
137+ resolve ( undefined ) ;
148138 } ) ;
139+ } ) ;
149140}
150141
151142/**
152143 * Extract the contents of a rar archive.
153144 */
154- export async function extractRar ( sourceFile : string , destinationFile : string ) : Promise < void > {
155- return new Promise ( async ( resolve , reject ) => {
156- const proc = spawn (
157- 'unrar' ,
158- [ 'x' , sourceFile , destinationFile ]
159- ) ;
160-
161- proc . on ( 'exit' , ( code ) => {
162- if ( code !== 0 ) {
163- reject ( new Error ( `Failed to extract rar archive. Exit code: ${ code } ` ) ) ;
164- }
165- resolve ( undefined ) ;
166- } ) ;
145+ export async function extractRar (
146+ sourceFile : string ,
147+ destinationFile : string ,
148+ ) : Promise < void > {
149+ return new Promise ( async ( resolve , reject ) => {
150+ const proc = spawn ( 'unrar' , [ 'x' , sourceFile , destinationFile ] ) ;
151+
152+ proc . on ( 'exit' , ( code ) => {
153+ if ( code !== 0 ) {
154+ reject ( new Error ( `Failed to extract rar archive. Exit code: ${ code } ` ) ) ;
155+ }
156+ resolve ( undefined ) ;
167157 } ) ;
158+ } ) ;
168159}
169160
170161/**
171162 * Create a zip archive from a directory recursively.
172163 */
173- export async function createZip ( sourceFile : string , destinationFile : string ) : Promise < void > {
174- return new Promise ( async ( resolve , reject ) => {
175- destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
176-
177- const proc = spawn (
178- 'zip' ,
179- [ '-r' , destinationFile , sourceFile ]
164+ export async function createZip (
165+ sourceFile : string ,
166+ destinationFile : string ,
167+ ) : Promise < void > {
168+ return new Promise ( async ( resolve , reject ) => {
169+ destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
170+
171+ const proc = spawn ( 'zip' , [ '-r' , destinationFile , sourceFile ] ) ;
172+
173+ proc . on ( 'exit' , ( code ) => {
174+ if ( code !== 0 ) {
175+ reject (
176+ new Error (
177+ `Failed to create zip archive from directory. Exit code: ${ code } ` ,
178+ ) ,
180179 ) ;
181-
182- proc . on ( 'exit' , code => {
183- if ( code !== 0 ) {
184- reject ( new Error ( `Failed to create zip archive from directory. Exit code: ${ code } ` ) ) ;
185- }
186- resolve ( undefined ) ;
187- } ) ;
180+ }
181+ resolve ( undefined ) ;
188182 } ) ;
183+ } ) ;
189184}
190185
191186/**
192187 * Extract the contents of a zip archive.
193188 */
194- export async function extractZip ( sourceFile : string , destinationFile : string ) : Promise < void > {
195- return new Promise ( async ( resolve , reject ) => {
196- destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
197-
198- const proc = spawn (
199- 'unzip' ,
200- [ sourceFile , '-d' , destinationFile ]
201- ) ;
202-
203- proc . on ( 'exit' , code => {
204- if ( code !== 0 ) {
205- reject ( new Error ( `Failed to extract zip archive. Exit code: ${ code } ` ) ) ;
206- }
207- resolve ( undefined ) ;
208- } ) ;
189+ export async function extractZip (
190+ sourceFile : string ,
191+ destinationFile : string ,
192+ ) : Promise < void > {
193+ return new Promise ( async ( resolve , reject ) => {
194+ destinationFile = path . resolve ( path . normalize ( destinationFile ) ) ;
195+
196+ const proc = spawn ( 'unzip' , [ sourceFile , '-d' , destinationFile ] ) ;
197+
198+ proc . on ( 'exit' , ( code ) => {
199+ if ( code !== 0 ) {
200+ reject ( new Error ( `Failed to extract zip archive. Exit code: ${ code } ` ) ) ;
201+ }
202+ resolve ( undefined ) ;
209203 } ) ;
204+ } ) ;
210205}
0 commit comments