Skip to content

Commit 2cc8f94

Browse files
committed
Narrow Uint8Array type, close #307, #308
1 parent c81171d commit 2cc8f94

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/deflate.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class Deflate {
121121
* Chunks of output data, if {@link Deflate.onData} not overridden.
122122
* @internal
123123
*/
124-
chunks: Uint8Array[];
124+
chunks: Uint8Array<ArrayBuffer>[];
125125

126126
private strm: ZStream;
127127

@@ -130,7 +130,7 @@ class Deflate {
130130
* and {@link Deflate.onEnd} handlers. Filled after you push last chunk
131131
* (call {@link Deflate.push} with {@link Z_FINISH} / `true` param).
132132
*/
133-
result: Uint8Array;
133+
result: Uint8Array<ArrayBuffer>;
134134

135135
/**
136136
* Creates a new deflator instance with the specified params. Throws an
@@ -320,7 +320,7 @@ class Deflate {
320320
* By default, stores data blocks in the {@link Deflate.chunks} property and glues
321321
* them in {@link Deflate.onEnd}. Override this handler if you need another behaviour.
322322
*/
323-
onData(chunk: Uint8Array): void {
323+
onData(chunk: Uint8Array<ArrayBuffer>): void {
324324
this.chunks.push(chunk);
325325
}
326326

@@ -355,7 +355,7 @@ class Deflate {
355355
* console.log(deflate(data))
356356
* ```
357357
*/
358-
function deflate(input: DeflateInput, options: DeflateOptions = {}): Uint8Array {
358+
function deflate(input: DeflateInput, options: DeflateOptions = {}): Uint8Array<ArrayBuffer> {
359359
const deflator = new Deflate(options);
360360

361361
deflator.push(input, true);
@@ -371,7 +371,7 @@ function deflate(input: DeflateInput, options: DeflateOptions = {}): Uint8Array
371371
* The same as {@link deflate}, but creates raw data without a wrapper
372372
* (header and adler32 crc).
373373
*/
374-
function deflateRaw(input: DeflateInput, options: DeflateOptions = {}): Uint8Array {
374+
function deflateRaw(input: DeflateInput, options: DeflateOptions = {}): Uint8Array<ArrayBuffer> {
375375
return deflate(input, Object.assign({}, options, { raw: true }));
376376
}
377377

@@ -380,7 +380,7 @@ function deflateRaw(input: DeflateInput, options: DeflateOptions = {}): Uint8Arr
380380
* The same as {@link deflate}, but creates a gzip wrapper instead of
381381
* a deflate one.
382382
*/
383-
function gzip(input: DeflateInput, options: DeflateOptions = {}): Uint8Array {
383+
function gzip(input: DeflateInput, options: DeflateOptions = {}): Uint8Array<ArrayBuffer> {
384384
return deflate(input, Object.assign({}, options, { gzip: true }));
385385
}
386386

src/inflate.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Inflate {
8888
* Chunks of output data, if {@link Inflate.onData} not overridden.
8989
* @internal
9090
*/
91-
chunks: Uint8Array[];
91+
chunks: Uint8Array<ArrayBuffer>[];
9292

9393
private strm: ZStream;
9494

@@ -97,7 +97,7 @@ class Inflate {
9797
* and {@link Inflate.onEnd} handlers. Filled after you push last chunk
9898
* (call {@link Inflate.push} with {@link Z_FINISH} / `true` param).
9999
*/
100-
result: Uint8Array;
100+
result: Uint8Array<ArrayBuffer>;
101101

102102
/**
103103
* Creates a new inflator instance with the specified params. Throws an
@@ -384,7 +384,7 @@ class Inflate {
384384
*
385385
* @param chunk output data.
386386
*/
387-
onData(chunk: Uint8Array): void {
387+
onData(chunk: Uint8Array<ArrayBuffer>): void {
388388
this.chunks.push(chunk);
389389
}
390390

@@ -429,7 +429,7 @@ class Inflate {
429429
function inflate<O extends InflateOptions & { toText?: boolean }>(
430430
input: InflateInput,
431431
options: O = {} as O
432-
): O extends { toText: true } ? string : Uint8Array {
432+
): O extends { toText: true } ? string : Uint8Array<ArrayBuffer> {
433433
const inflator = new Inflate(options);
434434

435435
inflator.push(input, true);
@@ -440,7 +440,7 @@ function inflate<O extends InflateOptions & { toText?: boolean }>(
440440
const result = inflator.result;
441441

442442
return (options.toText ? new TextDecoder().decode(result) : result) as
443-
O extends { toText: true } ? string : Uint8Array;
443+
O extends { toText: true } ? string : Uint8Array<ArrayBuffer>;
444444
}
445445

446446

@@ -451,7 +451,7 @@ function inflate<O extends InflateOptions & { toText?: boolean }>(
451451
function inflateRaw<O extends InflateOptions & { toText?: boolean }>(
452452
input: InflateInput,
453453
options: O = {} as O
454-
): O extends { toText: true } ? string : Uint8Array {
454+
): O extends { toText: true } ? string : Uint8Array<ArrayBuffer> {
455455
return inflate<O>(input, { ...options, raw: true } as O);
456456
}
457457

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Join array of chunks to single array.
2-
export const flattenChunks = (chunks: Uint8Array[]): Uint8Array => {
2+
export const flattenChunks = (chunks: Uint8Array<ArrayBuffer>[]): Uint8Array<ArrayBuffer> => {
33
const result = new Uint8Array(chunks.reduce((len, chunk) => len + chunk.length, 0));
44
let pos = 0;
55

src/zlib.d.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare class ZStream {
2525
next_in: number;
2626
avail_in: number;
2727
total_in: number;
28-
output: Uint8Array;
28+
output: Uint8Array<ArrayBuffer>;
2929
next_out: number;
3030
avail_out: number;
3131
total_out: number;

0 commit comments

Comments
 (0)