Skip to content

Commit 9183f3a

Browse files
committed
feat(zlib): implement async methods (cont.)
Signed-off-by: Sam Gammon <sam@elide.dev>
1 parent a585e72 commit 9183f3a

File tree

1 file changed

+65
-4
lines changed
  • elide/runtime/js/modules/zlib

1 file changed

+65
-4
lines changed

elide/runtime/js/modules/zlib/zlib.ts

+65-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ export function createInflate(options?: any): Inflate {
7272
return intrinsic().createInflate(options);
7373
}
7474

75+
/**
76+
* Creates a readable stream which decompresses data using the zip algorithm.
77+
*
78+
* @param options Zlib options to apply to this stream. Optional.
79+
* @returns Inflation stream
80+
*/
81+
export function createUnzip(options?: any): Inflate {
82+
return intrinsic().createUnzip(options);
83+
}
84+
7585
/**
7686
* Creates a writable stream which compresses data using the Brotli algorithm.
7787
*
@@ -97,7 +107,7 @@ export function createBrotliDecompress(options?: any): Inflate {
97107
*
98108
* @param data The data to compress
99109
* @param options Zlib options to apply to this compression. Optional.
100-
* @returns The compressed data
110+
* @param cbk Callback to invoke when the operation completes, and which receives the resulting data.
101111
*/
102112
export function deflate(
103113
data: string | Buffer | DataView | any,
@@ -125,7 +135,7 @@ export function deflateSync(data: string | Buffer | DataView | any, options?: an
125135
*
126136
* @param data The data to decompress
127137
* @param options Zlib options to apply to this compression. Optional.
128-
* @returns The decompressed data
138+
* @param cbk Callback to invoke when the operation completes, and which receives the resulting data.
129139
*/
130140
export function inflate(
131141
data: string | Buffer | DataView | any,
@@ -148,6 +158,23 @@ export function inflateSync(data: string | Buffer | DataView | any, options?: an
148158
return intrinsic().inflateSync(data, options);
149159
}
150160

161+
/**
162+
* Asynchronously compresses the given data using the gzip algorithm.
163+
*
164+
* @param data The data to compress
165+
* @param options Zlib options to apply to this compression. Optional.
166+
* @param cbk Callback to invoke when the operation completes, and which receives the resulting data.
167+
*/
168+
export function gzip(
169+
data: string | Buffer | DataView | any,
170+
optionsOrCbk?: any,
171+
cbk?: (errOrResult: Error | BufferLike) => void,
172+
): Buffer {
173+
const callback = cbk || optionsOrCbk;
174+
const opts = cbk ? optionsOrCbk : undefined;
175+
return intrinsic().gzip(data, opts, callback);
176+
}
177+
151178
/**
152179
* Synchronously compresses the given data using the gzip algorithm.
153180
*
@@ -159,6 +186,23 @@ export function gzipSync(data: string | Buffer | DataView | any, options?: any):
159186
return intrinsic().gzipSync(data, options);
160187
}
161188

189+
/**
190+
* Asynchronously decompresses the given data using the gzip algorithm.
191+
*
192+
* @param data The data to decompress
193+
* @param options Zlib options to apply to this compression. Optional.
194+
* @param cbk Callback to invoke when the operation completes, and which receives the resulting data.
195+
*/
196+
export function gunzip(
197+
data: string | Buffer | DataView | any,
198+
optionsOrCbk?: any,
199+
cbk?: (errOrResult: Error | BufferLike) => void,
200+
): Buffer {
201+
const callback = cbk || optionsOrCbk;
202+
const opts = cbk ? optionsOrCbk : undefined;
203+
return intrinsic().gunzip(data, opts, callback);
204+
}
205+
162206
/**
163207
* Synchronously decompresses the given data using the gzip algorithm.
164208
*
@@ -170,6 +214,23 @@ export function gunzipSync(data: string | Buffer | DataView | any, options?: any
170214
return intrinsic().gunzipSync(data, options);
171215
}
172216

217+
/**
218+
* Asynchronously decompresses the given data using the zip algorithm.
219+
*
220+
* @param data The data to decompress
221+
* @param options Zlib options to apply to this compression. Optional.
222+
* @param cbk Callback to invoke when the operation completes, and which receives the resulting data.
223+
*/
224+
export function unzip(
225+
data: string | Buffer | DataView | any,
226+
optionsOrCbk?: any,
227+
cbk?: (errOrResult: Error | BufferLike) => void,
228+
): Buffer {
229+
const callback = cbk || optionsOrCbk;
230+
const opts = cbk ? optionsOrCbk : undefined;
231+
return intrinsic().unzip(data, opts, callback);
232+
}
233+
173234
/**
174235
* Synchronously decompresses the given data using the zip algorithm.
175236
*
@@ -186,7 +247,7 @@ export function unzipSync(data: string | Buffer | DataView | any, options?: any)
186247
*
187248
* @param data The data to compress
188249
* @param options Brotli options to apply to this compression. Optional.
189-
* @returns The compressed data
250+
* @param cbk Callback to invoke when the operation completes, and which receives the resulting data.
190251
*/
191252
export function brotliCompress(
192253
data: string | Buffer | DataView | any,
@@ -214,7 +275,7 @@ export function brotliCompressSync(data: string | Buffer | DataView | any, optio
214275
*
215276
* @param data The data to decompress
216277
* @param options Brotli options to apply to this compression. Optional.
217-
* @returns The decompressed data
278+
* @param cbk Callback to invoke when the operation completes, and which receives the resulting data.
218279
*/
219280
export function brotliDecompress(
220281
data: string | Buffer | DataView | any,

0 commit comments

Comments
 (0)