1
1
import { runCommand } from '@stacksjs/cli'
2
+ import type { Result } from '@stacksjs/error-handling'
3
+ import type { CommandError , Subprocess } from '@stacksjs/types'
2
4
import type { ZlibCompressionOptions } from 'bun'
3
5
4
6
interface ZipOptions {
5
7
cwd ?: string
6
8
}
7
9
8
- export async function zip ( from : string | string [ ] , to ?: string , options ?: ZipOptions ) {
10
+ export async function zip (
11
+ from : string | string [ ] ,
12
+ to ?: string ,
13
+ options ?: ZipOptions ,
14
+ ) : Promise < Result < Subprocess , CommandError > > {
9
15
const toPath = to || 'archive.zip'
10
16
const fromPath = Array . isArray ( from ) ? from . join ( ' ' ) : from
11
17
@@ -14,40 +20,40 @@ export async function zip(from: string | string[], to?: string, options?: ZipOpt
14
20
return runCommand ( `zip -r ${ to } ${ from } ` , options )
15
21
}
16
22
17
- export async function unzip ( paths : string | string [ ] ) {
23
+ export async function unzip ( paths : string | string [ ] ) : Promise < Result < Subprocess , CommandError > > {
18
24
if ( Array . isArray ( paths ) ) return runCommand ( `unzip ${ paths . join ( ' ' ) } ` )
19
25
20
26
return runCommand ( `unzip ${ paths } ` )
21
27
}
22
28
23
- export function archive ( paths : string | string [ ] ) {
29
+ export function archive ( paths : string | string [ ] ) : Promise < Result < Subprocess , CommandError > > {
24
30
return zip ( paths )
25
31
}
26
32
27
- export function unarchive ( paths : string | string [ ] ) {
33
+ export function unarchive ( paths : string | string [ ] ) : Promise < Result < Subprocess , CommandError > > {
28
34
return unzip ( paths )
29
35
}
30
36
31
- export function compress ( paths : string [ ] ) {
37
+ export function compress ( paths : string [ ] ) : Promise < Result < Subprocess , CommandError > > {
32
38
return zip ( paths )
33
39
}
34
40
35
- export function decompress ( paths : string | string [ ] ) {
41
+ export function decompress ( paths : string | string [ ] ) : Promise < Result < Subprocess , CommandError > > {
36
42
return unzip ( paths )
37
43
}
38
44
39
- export function gzipSync ( data : Uint8Array , options ?: ZlibCompressionOptions ) {
45
+ export function gzipSync ( data : Uint8Array , options ?: ZlibCompressionOptions ) : Uint8Array {
40
46
return Bun . gzipSync ( data , options ) // buffer extends Uint8Array
41
47
}
42
48
43
- export function gunzipSync ( data : Uint8Array ) {
49
+ export function gunzipSync ( data : Uint8Array ) : Uint8Array {
44
50
return Bun . gunzipSync ( data ) // decompressed
45
51
}
46
52
47
- export function deflateSync ( data : Uint8Array , options ?: ZlibCompressionOptions ) {
53
+ export function deflateSync ( data : Uint8Array , options ?: ZlibCompressionOptions ) : Uint8Array {
48
54
return Bun . deflateSync ( data , options ) // compressed
49
55
}
50
56
51
- export function inflateSync ( data : Uint8Array ) {
57
+ export function inflateSync ( data : Uint8Array ) : Uint8Array {
52
58
return Bun . inflateSync ( data ) // decompressed
53
59
}
0 commit comments