-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
71 lines (56 loc) · 1.47 KB
/
index.d.ts
File metadata and controls
71 lines (56 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
A TransformStream that counts bytes passing through without modifying the data.
@example
```
import ByteCounterStream from 'byte-counter';
const counter = new ByteCounterStream();
const response = await fetch('https://example.com/large-file.zip');
await response.body
.pipeThrough(counter)
.pipeTo(new WritableStream({
write(chunk) {
// Process chunk
},
close() {
console.log(`Downloaded ${counter.count} bytes`);
}
}));
```
@example
```
import ByteCounterStream from 'byte-counter';
const counter = new ByteCounterStream();
const encoder = new TextEncoder();
const writer = counter.writable.getWriter();
await writer.write(encoder.encode('Hello '));
await writer.write(encoder.encode('World'));
await writer.close();
console.log(counter.count);
//=> 11
```
*/
export default class ByteCounterStream implements ReadableWritablePair<Uint8Array, Uint8Array> {
readonly readable: ReadableStream<Uint8Array>;
readonly writable: WritableStream<Uint8Array>;
/**
The number of bytes that have passed through the stream.
*/
readonly count: number;
}
/**
Calculate the byte length of some data.
Strings are measured as UTF-8 bytes.
@param data - The data to measure.
@returns The byte length of the data.
@example
```
import {byteLength} from 'byte-counter';
byteLength('Hello');
//=> 5
byteLength('Hello 👋');
//=> 10
byteLength(new Uint8Array([1, 2, 3]));
//=> 3
```
*/
export function byteLength(data: string | ArrayBuffer | SharedArrayBuffer | ArrayBufferView): number;