@mtkruto/node 0.132.0 → 0.132.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/0_deps.d.ts +2 -2
- package/esm/0_deps.d.ts.map +1 -1
- package/esm/0_deps.js +2 -2
- package/esm/2_connection.d.ts +2 -0
- package/esm/2_connection.d.ts.map +1 -1
- package/esm/2_connection.js +2 -0
- package/esm/3_transport.d.ts +1 -0
- package/esm/3_transport.d.ts.map +1 -1
- package/esm/3_transport.js +1 -0
- package/esm/connection/0_get_tls_header.d.ts +2 -0
- package/esm/connection/0_get_tls_header.d.ts.map +1 -0
- package/esm/connection/0_get_tls_header.js +152 -0
- package/esm/connection/1_connection_tcp.node.d.ts.map +1 -1
- package/esm/connection/1_connection_tcp.node.js +4 -4
- package/esm/connection/1_connection_tls.node.d.ts +31 -0
- package/esm/connection/1_connection_tls.node.d.ts.map +1 -0
- package/esm/connection/1_connection_tls.node.js +199 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/write_all.d.ts +52 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/write_all.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/write_all.js +61 -0
- package/esm/session/2_session_encrypted.d.ts.map +1 -1
- package/esm/session/2_session_encrypted.js +4 -1
- package/esm/transport/0_obfuscation.d.ts +5 -1
- package/esm/transport/0_obfuscation.d.ts.map +1 -1
- package/esm/transport/0_obfuscation.js +17 -4
- package/esm/transport/1_transport_intermediate.d.ts +7 -20
- package/esm/transport/1_transport_intermediate.d.ts.map +1 -1
- package/esm/transport/1_transport_intermediate.js +18 -7
- package/esm/transport/2_transport_provider_mtproxy.d.ts +23 -0
- package/esm/transport/2_transport_provider_mtproxy.d.ts.map +1 -0
- package/esm/transport/2_transport_provider_mtproxy.js +51 -0
- package/esm/transport/2_transport_provider_web_socket.js +1 -1
- package/esm/utilities/1_crypto.d.ts +1 -0
- package/esm/utilities/1_crypto.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +4 -0
- package/package.json +1 -1
- package/script/0_deps.d.ts +2 -2
- package/script/0_deps.d.ts.map +1 -1
- package/script/0_deps.js +4 -3
- package/script/2_connection.d.ts +2 -0
- package/script/2_connection.d.ts.map +1 -1
- package/script/2_connection.js +2 -0
- package/script/3_transport.d.ts +1 -0
- package/script/3_transport.d.ts.map +1 -1
- package/script/3_transport.js +1 -0
- package/script/connection/0_get_tls_header.d.ts +2 -0
- package/script/connection/0_get_tls_header.d.ts.map +1 -0
- package/script/connection/0_get_tls_header.js +188 -0
- package/script/connection/1_connection_tcp.node.d.ts.map +1 -1
- package/script/connection/1_connection_tcp.node.js +4 -4
- package/script/connection/1_connection_tls.node.d.ts +31 -0
- package/script/connection/1_connection_tls.node.d.ts.map +1 -0
- package/script/connection/1_connection_tls.node.js +203 -0
- package/script/deps/jsr.io/@std/io/0.225.3/write_all.d.ts +52 -0
- package/script/deps/jsr.io/@std/io/0.225.3/write_all.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.3/write_all.js +65 -0
- package/script/session/2_session_encrypted.d.ts.map +1 -1
- package/script/session/2_session_encrypted.js +4 -1
- package/script/transport/0_obfuscation.d.ts +5 -1
- package/script/transport/0_obfuscation.d.ts.map +1 -1
- package/script/transport/0_obfuscation.js +16 -3
- package/script/transport/1_transport_intermediate.d.ts +7 -20
- package/script/transport/1_transport_intermediate.d.ts.map +1 -1
- package/script/transport/1_transport_intermediate.js +52 -8
- package/script/transport/2_transport_provider_mtproxy.d.ts +23 -0
- package/script/transport/2_transport_provider_mtproxy.d.ts.map +1 -0
- package/script/transport/2_transport_provider_mtproxy.js +54 -0
- package/script/transport/2_transport_provider_web_socket.js +1 -1
- package/script/utilities/1_crypto.d.ts +1 -0
- package/script/utilities/1_crypto.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +5 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/_constants.d.ts +0 -3
- package/esm/deps/jsr.io/@std/io/0.225.3/_constants.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/io/0.225.3/_constants.js +0 -4
- package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts +0 -80
- package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.js +0 -96
- package/script/deps/jsr.io/@std/io/0.225.3/_constants.d.ts +0 -3
- package/script/deps/jsr.io/@std/io/0.225.3/_constants.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/io/0.225.3/_constants.js +0 -7
- package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts +0 -80
- package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.js +0 -100
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.CTR = void 0;
|
|
37
|
+
exports.hmacSha256 = hmacSha256;
|
|
37
38
|
/**
|
|
38
39
|
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
39
40
|
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
@@ -115,3 +116,7 @@ class CTR {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
exports.CTR = CTR;
|
|
119
|
+
async function hmacSha256(data, secret) {
|
|
120
|
+
const key = await dntShim.crypto.subtle.importKey("raw", secret, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
121
|
+
return new Uint8Array(await dntShim.crypto.subtle.sign("HMAC", key, data.buffer));
|
|
122
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_constants.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/io/0.225.3/_constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,eAAO,MAAM,mBAAmB,QAAY,CAAC"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { Reader, ReaderSync } from "./types.js";
|
|
2
|
-
export type { Reader, ReaderSync };
|
|
3
|
-
/**
|
|
4
|
-
* Turns a {@linkcode Reader} into an async iterator.
|
|
5
|
-
*
|
|
6
|
-
* @example Usage
|
|
7
|
-
* ```ts no-assert
|
|
8
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
9
|
-
*
|
|
10
|
-
* using file = await Deno.open("README.md");
|
|
11
|
-
* for await (const chunk of iterateReader(file)) {
|
|
12
|
-
* console.log(chunk);
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @example Usage with buffer size
|
|
17
|
-
* ```ts no-assert
|
|
18
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
19
|
-
*
|
|
20
|
-
* using file = await Deno.open("README.md");
|
|
21
|
-
* const iter = iterateReader(file, {
|
|
22
|
-
* bufSize: 1024 * 1024
|
|
23
|
-
* });
|
|
24
|
-
* for await (const chunk of iter) {
|
|
25
|
-
* console.log(chunk);
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param reader The reader to read from
|
|
30
|
-
* @param options The options
|
|
31
|
-
* @param options.bufSize The size of the buffer to use
|
|
32
|
-
* @returns The async iterator of Uint8Array chunks
|
|
33
|
-
*/
|
|
34
|
-
export declare function iterateReader(reader: Reader, options?: {
|
|
35
|
-
bufSize?: number;
|
|
36
|
-
}): AsyncIterableIterator<Uint8Array>;
|
|
37
|
-
/**
|
|
38
|
-
* Turns a {@linkcode ReaderSync} into an iterator.
|
|
39
|
-
*
|
|
40
|
-
* @example Usage
|
|
41
|
-
* ```ts
|
|
42
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
43
|
-
* import { assert } from "@std/assert/assert"
|
|
44
|
-
*
|
|
45
|
-
* using file = Deno.openSync("README.md");
|
|
46
|
-
* for (const chunk of iterateReaderSync(file)) {
|
|
47
|
-
* assert(chunk instanceof Uint8Array);
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* Second argument can be used to tune size of a buffer.
|
|
52
|
-
* Default size of the buffer is 32kB.
|
|
53
|
-
*
|
|
54
|
-
* @example Usage with buffer size
|
|
55
|
-
* ```ts
|
|
56
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
57
|
-
* import { assert } from "@std/assert/assert"
|
|
58
|
-
*
|
|
59
|
-
* using file = await Deno.open("README.md");
|
|
60
|
-
* const iter = iterateReaderSync(file, {
|
|
61
|
-
* bufSize: 1024 * 1024
|
|
62
|
-
* });
|
|
63
|
-
* for (const chunk of iter) {
|
|
64
|
-
* assert(chunk instanceof Uint8Array);
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* Iterator uses an internal buffer of fixed size for efficiency; it returns
|
|
69
|
-
* a view on that buffer on each iteration. It is therefore caller's
|
|
70
|
-
* responsibility to copy contents of the buffer if needed; otherwise the
|
|
71
|
-
* next iteration will overwrite contents of previously returned chunk.
|
|
72
|
-
*
|
|
73
|
-
* @param reader The reader to read from
|
|
74
|
-
* @param options The options
|
|
75
|
-
* @returns The iterator of Uint8Array chunks
|
|
76
|
-
*/
|
|
77
|
-
export declare function iterateReaderSync(reader: ReaderSync, options?: {
|
|
78
|
-
bufSize?: number;
|
|
79
|
-
}): IterableIterator<Uint8Array>;
|
|
80
|
-
//# sourceMappingURL=iterate_reader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iterate_reader.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/io/0.225.3/iterate_reader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAuB,aAAa,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,qBAAqB,CAAC,UAAU,CAAC,CAWnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAiB,iBAAiB,CAChC,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,gBAAgB,CAAC,UAAU,CAAC,CAW9B"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
import { DEFAULT_BUFFER_SIZE } from "./_constants.js";
|
|
4
|
-
/**
|
|
5
|
-
* Turns a {@linkcode Reader} into an async iterator.
|
|
6
|
-
*
|
|
7
|
-
* @example Usage
|
|
8
|
-
* ```ts no-assert
|
|
9
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
10
|
-
*
|
|
11
|
-
* using file = await Deno.open("README.md");
|
|
12
|
-
* for await (const chunk of iterateReader(file)) {
|
|
13
|
-
* console.log(chunk);
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @example Usage with buffer size
|
|
18
|
-
* ```ts no-assert
|
|
19
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
20
|
-
*
|
|
21
|
-
* using file = await Deno.open("README.md");
|
|
22
|
-
* const iter = iterateReader(file, {
|
|
23
|
-
* bufSize: 1024 * 1024
|
|
24
|
-
* });
|
|
25
|
-
* for await (const chunk of iter) {
|
|
26
|
-
* console.log(chunk);
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param reader The reader to read from
|
|
31
|
-
* @param options The options
|
|
32
|
-
* @param options.bufSize The size of the buffer to use
|
|
33
|
-
* @returns The async iterator of Uint8Array chunks
|
|
34
|
-
*/
|
|
35
|
-
export async function* iterateReader(reader, options) {
|
|
36
|
-
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
|
37
|
-
const b = new Uint8Array(bufSize);
|
|
38
|
-
while (true) {
|
|
39
|
-
const result = await reader.read(b);
|
|
40
|
-
if (result === null) {
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
yield b.slice(0, result);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Turns a {@linkcode ReaderSync} into an iterator.
|
|
48
|
-
*
|
|
49
|
-
* @example Usage
|
|
50
|
-
* ```ts
|
|
51
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
52
|
-
* import { assert } from "@std/assert/assert"
|
|
53
|
-
*
|
|
54
|
-
* using file = Deno.openSync("README.md");
|
|
55
|
-
* for (const chunk of iterateReaderSync(file)) {
|
|
56
|
-
* assert(chunk instanceof Uint8Array);
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* Second argument can be used to tune size of a buffer.
|
|
61
|
-
* Default size of the buffer is 32kB.
|
|
62
|
-
*
|
|
63
|
-
* @example Usage with buffer size
|
|
64
|
-
* ```ts
|
|
65
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
66
|
-
* import { assert } from "@std/assert/assert"
|
|
67
|
-
*
|
|
68
|
-
* using file = await Deno.open("README.md");
|
|
69
|
-
* const iter = iterateReaderSync(file, {
|
|
70
|
-
* bufSize: 1024 * 1024
|
|
71
|
-
* });
|
|
72
|
-
* for (const chunk of iter) {
|
|
73
|
-
* assert(chunk instanceof Uint8Array);
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* Iterator uses an internal buffer of fixed size for efficiency; it returns
|
|
78
|
-
* a view on that buffer on each iteration. It is therefore caller's
|
|
79
|
-
* responsibility to copy contents of the buffer if needed; otherwise the
|
|
80
|
-
* next iteration will overwrite contents of previously returned chunk.
|
|
81
|
-
*
|
|
82
|
-
* @param reader The reader to read from
|
|
83
|
-
* @param options The options
|
|
84
|
-
* @returns The iterator of Uint8Array chunks
|
|
85
|
-
*/
|
|
86
|
-
export function* iterateReaderSync(reader, options) {
|
|
87
|
-
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
|
88
|
-
const b = new Uint8Array(bufSize);
|
|
89
|
-
while (true) {
|
|
90
|
-
const result = reader.readSync(b);
|
|
91
|
-
if (result === null) {
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
yield b.slice(0, result);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_constants.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/io/0.225.3/_constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,eAAO,MAAM,mBAAmB,QAAY,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
|
-
// This module is browser compatible.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.DEFAULT_BUFFER_SIZE = exports.DEFAULT_CHUNK_SIZE = void 0;
|
|
6
|
-
exports.DEFAULT_CHUNK_SIZE = 16_640;
|
|
7
|
-
exports.DEFAULT_BUFFER_SIZE = 32 * 1024;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { Reader, ReaderSync } from "./types.js";
|
|
2
|
-
export type { Reader, ReaderSync };
|
|
3
|
-
/**
|
|
4
|
-
* Turns a {@linkcode Reader} into an async iterator.
|
|
5
|
-
*
|
|
6
|
-
* @example Usage
|
|
7
|
-
* ```ts no-assert
|
|
8
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
9
|
-
*
|
|
10
|
-
* using file = await Deno.open("README.md");
|
|
11
|
-
* for await (const chunk of iterateReader(file)) {
|
|
12
|
-
* console.log(chunk);
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @example Usage with buffer size
|
|
17
|
-
* ```ts no-assert
|
|
18
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
19
|
-
*
|
|
20
|
-
* using file = await Deno.open("README.md");
|
|
21
|
-
* const iter = iterateReader(file, {
|
|
22
|
-
* bufSize: 1024 * 1024
|
|
23
|
-
* });
|
|
24
|
-
* for await (const chunk of iter) {
|
|
25
|
-
* console.log(chunk);
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param reader The reader to read from
|
|
30
|
-
* @param options The options
|
|
31
|
-
* @param options.bufSize The size of the buffer to use
|
|
32
|
-
* @returns The async iterator of Uint8Array chunks
|
|
33
|
-
*/
|
|
34
|
-
export declare function iterateReader(reader: Reader, options?: {
|
|
35
|
-
bufSize?: number;
|
|
36
|
-
}): AsyncIterableIterator<Uint8Array>;
|
|
37
|
-
/**
|
|
38
|
-
* Turns a {@linkcode ReaderSync} into an iterator.
|
|
39
|
-
*
|
|
40
|
-
* @example Usage
|
|
41
|
-
* ```ts
|
|
42
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
43
|
-
* import { assert } from "@std/assert/assert"
|
|
44
|
-
*
|
|
45
|
-
* using file = Deno.openSync("README.md");
|
|
46
|
-
* for (const chunk of iterateReaderSync(file)) {
|
|
47
|
-
* assert(chunk instanceof Uint8Array);
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* Second argument can be used to tune size of a buffer.
|
|
52
|
-
* Default size of the buffer is 32kB.
|
|
53
|
-
*
|
|
54
|
-
* @example Usage with buffer size
|
|
55
|
-
* ```ts
|
|
56
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
57
|
-
* import { assert } from "@std/assert/assert"
|
|
58
|
-
*
|
|
59
|
-
* using file = await Deno.open("README.md");
|
|
60
|
-
* const iter = iterateReaderSync(file, {
|
|
61
|
-
* bufSize: 1024 * 1024
|
|
62
|
-
* });
|
|
63
|
-
* for (const chunk of iter) {
|
|
64
|
-
* assert(chunk instanceof Uint8Array);
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* Iterator uses an internal buffer of fixed size for efficiency; it returns
|
|
69
|
-
* a view on that buffer on each iteration. It is therefore caller's
|
|
70
|
-
* responsibility to copy contents of the buffer if needed; otherwise the
|
|
71
|
-
* next iteration will overwrite contents of previously returned chunk.
|
|
72
|
-
*
|
|
73
|
-
* @param reader The reader to read from
|
|
74
|
-
* @param options The options
|
|
75
|
-
* @returns The iterator of Uint8Array chunks
|
|
76
|
-
*/
|
|
77
|
-
export declare function iterateReaderSync(reader: ReaderSync, options?: {
|
|
78
|
-
bufSize?: number;
|
|
79
|
-
}): IterableIterator<Uint8Array>;
|
|
80
|
-
//# sourceMappingURL=iterate_reader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iterate_reader.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/io/0.225.3/iterate_reader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAuB,aAAa,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,qBAAqB,CAAC,UAAU,CAAC,CAWnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAiB,iBAAiB,CAChC,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,gBAAgB,CAAC,UAAU,CAAC,CAW9B"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
|
-
// This module is browser compatible.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.iterateReader = iterateReader;
|
|
6
|
-
exports.iterateReaderSync = iterateReaderSync;
|
|
7
|
-
const _constants_js_1 = require("./_constants.js");
|
|
8
|
-
/**
|
|
9
|
-
* Turns a {@linkcode Reader} into an async iterator.
|
|
10
|
-
*
|
|
11
|
-
* @example Usage
|
|
12
|
-
* ```ts no-assert
|
|
13
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
14
|
-
*
|
|
15
|
-
* using file = await Deno.open("README.md");
|
|
16
|
-
* for await (const chunk of iterateReader(file)) {
|
|
17
|
-
* console.log(chunk);
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @example Usage with buffer size
|
|
22
|
-
* ```ts no-assert
|
|
23
|
-
* import { iterateReader } from "@std/io/iterate-reader";
|
|
24
|
-
*
|
|
25
|
-
* using file = await Deno.open("README.md");
|
|
26
|
-
* const iter = iterateReader(file, {
|
|
27
|
-
* bufSize: 1024 * 1024
|
|
28
|
-
* });
|
|
29
|
-
* for await (const chunk of iter) {
|
|
30
|
-
* console.log(chunk);
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @param reader The reader to read from
|
|
35
|
-
* @param options The options
|
|
36
|
-
* @param options.bufSize The size of the buffer to use
|
|
37
|
-
* @returns The async iterator of Uint8Array chunks
|
|
38
|
-
*/
|
|
39
|
-
async function* iterateReader(reader, options) {
|
|
40
|
-
const bufSize = options?.bufSize ?? _constants_js_1.DEFAULT_BUFFER_SIZE;
|
|
41
|
-
const b = new Uint8Array(bufSize);
|
|
42
|
-
while (true) {
|
|
43
|
-
const result = await reader.read(b);
|
|
44
|
-
if (result === null) {
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
yield b.slice(0, result);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Turns a {@linkcode ReaderSync} into an iterator.
|
|
52
|
-
*
|
|
53
|
-
* @example Usage
|
|
54
|
-
* ```ts
|
|
55
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
56
|
-
* import { assert } from "@std/assert/assert"
|
|
57
|
-
*
|
|
58
|
-
* using file = Deno.openSync("README.md");
|
|
59
|
-
* for (const chunk of iterateReaderSync(file)) {
|
|
60
|
-
* assert(chunk instanceof Uint8Array);
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* Second argument can be used to tune size of a buffer.
|
|
65
|
-
* Default size of the buffer is 32kB.
|
|
66
|
-
*
|
|
67
|
-
* @example Usage with buffer size
|
|
68
|
-
* ```ts
|
|
69
|
-
* import { iterateReaderSync } from "@std/io/iterate-reader";
|
|
70
|
-
* import { assert } from "@std/assert/assert"
|
|
71
|
-
*
|
|
72
|
-
* using file = await Deno.open("README.md");
|
|
73
|
-
* const iter = iterateReaderSync(file, {
|
|
74
|
-
* bufSize: 1024 * 1024
|
|
75
|
-
* });
|
|
76
|
-
* for (const chunk of iter) {
|
|
77
|
-
* assert(chunk instanceof Uint8Array);
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* Iterator uses an internal buffer of fixed size for efficiency; it returns
|
|
82
|
-
* a view on that buffer on each iteration. It is therefore caller's
|
|
83
|
-
* responsibility to copy contents of the buffer if needed; otherwise the
|
|
84
|
-
* next iteration will overwrite contents of previously returned chunk.
|
|
85
|
-
*
|
|
86
|
-
* @param reader The reader to read from
|
|
87
|
-
* @param options The options
|
|
88
|
-
* @returns The iterator of Uint8Array chunks
|
|
89
|
-
*/
|
|
90
|
-
function* iterateReaderSync(reader, options) {
|
|
91
|
-
const bufSize = options?.bufSize ?? _constants_js_1.DEFAULT_BUFFER_SIZE;
|
|
92
|
-
const b = new Uint8Array(bufSize);
|
|
93
|
-
while (true) {
|
|
94
|
-
const result = reader.readSync(b);
|
|
95
|
-
if (result === null) {
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
yield b.slice(0, result);
|
|
99
|
-
}
|
|
100
|
-
}
|