@mtkruto/browser 0.132.0 → 0.133.0
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 +151 -0
- package/esm/connection/1_connection_tcp.d.ts.map +1 -1
- package/esm/connection/1_connection_tcp.js +21 -52
- package/esm/connection/1_connection_tls.d.ts +33 -0
- package/esm/connection/1_connection_tls.d.ts.map +1 -0
- package/esm/connection/1_connection_tls.js +203 -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 -1
- package/esm/transport/1_transport_intermediate.d.ts.map +1 -1
- package/esm/transport/1_transport_intermediate.js +17 -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 +154 -0
- package/script/connection/1_connection_tcp.d.ts.map +1 -1
- package/script/connection/1_connection_tcp.js +21 -52
- package/script/connection/1_connection_tls.d.ts +33 -0
- package/script/connection/1_connection_tls.d.ts.map +1 -0
- package/script/connection/1_connection_tls.js +207 -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 -1
- package/script/transport/1_transport_intermediate.d.ts.map +1 -1
- package/script/transport/1_transport_intermediate.js +16 -6
- 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
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { CTR } from "../1_utilities.js";
|
|
21
21
|
import type { Connection } from "../2_connection.js";
|
|
22
|
-
export
|
|
22
|
+
export interface GetObfuscationParametersParams {
|
|
23
|
+
dcId?: number;
|
|
24
|
+
secret?: Uint8Array;
|
|
25
|
+
}
|
|
26
|
+
export declare function getObfuscationParameters(protocol: number, connection: Connection, params?: GetObfuscationParametersParams): Promise<{
|
|
23
27
|
encryptionCTR: CTR;
|
|
24
28
|
decryptionCTR: CTR;
|
|
25
29
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0_obfuscation.d.ts","sourceRoot":"","sources":["../../src/transport/0_obfuscation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"0_obfuscation.d.ts","sourceRoot":"","sources":["../../src/transport/0_obfuscation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,GAAG,EAAsB,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,8BAA8B;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,8BAA8B;;;GAyD/H"}
|
|
@@ -22,7 +22,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.getObfuscationParameters = getObfuscationParameters;
|
|
23
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
24
24
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
25
|
-
async function getObfuscationParameters(protocol, connection) {
|
|
25
|
+
async function getObfuscationParameters(protocol, connection, params) {
|
|
26
26
|
let init;
|
|
27
27
|
while (true) {
|
|
28
28
|
init = (0, _0_deps_js_1.concat)([crypto.getRandomValues(new Uint8Array(56)), (0, _1_utilities_js_1.intToBytes)(protocol, 4, { byteOrder: "big", isSigned: false }), crypto.getRandomValues(new Uint8Array(4))]);
|
|
@@ -40,14 +40,27 @@ async function getObfuscationParameters(protocol, connection) {
|
|
|
40
40
|
}
|
|
41
41
|
break;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
if (params?.dcId !== undefined) {
|
|
44
|
+
init.set((0, _1_utilities_js_1.intToBytes)(params.dcId, 2, { byteOrder: "little" }), 60);
|
|
45
|
+
}
|
|
46
|
+
let secret = params?.secret;
|
|
47
|
+
if (secret !== undefined && secret.byteLength >= 17) {
|
|
48
|
+
secret = secret.subarray(1, 17);
|
|
49
|
+
}
|
|
50
|
+
let encryptKey = init.slice(8, 8 + 32);
|
|
44
51
|
const encryptIv = init.slice(40, 40 + 16);
|
|
52
|
+
if (secret) {
|
|
53
|
+
encryptKey = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([encryptKey, secret]));
|
|
54
|
+
}
|
|
45
55
|
const importedEncryptedKey = await _1_utilities_js_1.CTR.importKey(encryptKey);
|
|
46
56
|
const encryptionCTR = new _1_utilities_js_1.CTR(importedEncryptedKey, encryptIv);
|
|
47
57
|
const encryptedInit = await encryptionCTR.call(init);
|
|
48
58
|
const initRev = new Uint8Array(init).reverse();
|
|
49
|
-
|
|
59
|
+
let decryptKey = initRev.slice(8, 8 + 32);
|
|
50
60
|
const decryptIv = initRev.slice(40, 40 + 16);
|
|
61
|
+
if (secret) {
|
|
62
|
+
decryptKey = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([decryptKey, secret]));
|
|
63
|
+
}
|
|
51
64
|
const importedDecryptKey = await _1_utilities_js_1.CTR.importKey(decryptKey);
|
|
52
65
|
const decryptionCTR = new _1_utilities_js_1.CTR(importedDecryptKey, decryptIv);
|
|
53
66
|
await connection.write((0, _0_deps_js_1.concat)([init.subarray(0, 56), encryptedInit.subarray(56, 56 + 8)]));
|
|
@@ -19,9 +19,15 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import type { Connection } from "../2_connection.js";
|
|
21
21
|
import { Transport } from "./0_transport.js";
|
|
22
|
+
export interface TransportIntermediateParams {
|
|
23
|
+
isObfuscated?: boolean;
|
|
24
|
+
isPadded?: boolean;
|
|
25
|
+
dcId?: number;
|
|
26
|
+
secret?: Uint8Array;
|
|
27
|
+
}
|
|
22
28
|
export declare class TransportIntermediate extends Transport implements Transport {
|
|
23
29
|
#private;
|
|
24
|
-
constructor(connection: Connection,
|
|
30
|
+
constructor(connection: Connection, params?: TransportIntermediateParams);
|
|
25
31
|
initialize(): Promise<void>;
|
|
26
32
|
receive(): Promise<Uint8Array>;
|
|
27
33
|
send(buffer: Uint8Array): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_transport_intermediate.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_intermediate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,qBAAa,qBAAsB,SAAQ,SAAU,YAAW,SAAS;;
|
|
1
|
+
{"version":3,"file":"1_transport_intermediate.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_intermediate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,WAAW,2BAA2B;IAC1C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,qBAAa,qBAAsB,SAAQ,SAAU,YAAW,SAAS;;gBAO3D,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,2BAA2B;IASlE,UAAU;IAYV,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAiB9B,IAAI,CAAC,MAAM,EAAE,UAAU;CAW9B"}
|
|
@@ -26,18 +26,24 @@ const _0_obfuscation_js_1 = require("./0_obfuscation.js");
|
|
|
26
26
|
const _0_transport_js_1 = require("./0_transport.js");
|
|
27
27
|
class TransportIntermediate extends _0_transport_js_1.Transport {
|
|
28
28
|
#connection;
|
|
29
|
-
#
|
|
30
|
-
|
|
29
|
+
#isObfuscated;
|
|
30
|
+
#isPadded;
|
|
31
|
+
#dcId;
|
|
32
|
+
#secret;
|
|
33
|
+
constructor(connection, params) {
|
|
31
34
|
super();
|
|
32
35
|
this.#connection = connection;
|
|
33
|
-
this.#
|
|
36
|
+
this.#isObfuscated = params?.isObfuscated ?? false;
|
|
37
|
+
this.#isPadded = params?.isPadded ?? false;
|
|
38
|
+
this.#dcId = params?.dcId;
|
|
39
|
+
this.#secret = params?.secret;
|
|
34
40
|
}
|
|
35
41
|
async initialize() {
|
|
36
|
-
if (this.#
|
|
37
|
-
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEEEEEEEE, this.#connection);
|
|
42
|
+
if (this.#isObfuscated) {
|
|
43
|
+
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(this.#isPadded ? 0xDDDDDDDD : 0xEEEEEEEE, this.#connection, { dcId: this.#dcId, secret: this.#secret });
|
|
38
44
|
}
|
|
39
45
|
else {
|
|
40
|
-
await this.#connection.write(new Uint8Array([0xEE, 0xEE, 0xEE, 0xEE]));
|
|
46
|
+
await this.#connection.write(new Uint8Array(this.#isPadded ? [0xDD, 0xDD, 0xDD, 0xDD] : [0xEE, 0xEE, 0xEE, 0xEE]));
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
async receive() {
|
|
@@ -54,6 +60,10 @@ class TransportIntermediate extends _0_transport_js_1.Transport {
|
|
|
54
60
|
return await this.decrypt(buffer);
|
|
55
61
|
}
|
|
56
62
|
async send(buffer) {
|
|
63
|
+
if (this.#isPadded) {
|
|
64
|
+
const padding = crypto.getRandomValues(new Uint8Array(Math.abs((0, _1_utilities_js_1.getRandomId)(true) % 16)));
|
|
65
|
+
buffer = (0, _0_deps_js_1.concat)([buffer, padding]);
|
|
66
|
+
}
|
|
57
67
|
const length = (0, _1_utilities_js_1.intToBytes)(buffer.length, 4);
|
|
58
68
|
const data = (0, _0_deps_js_1.concat)([length, buffer]);
|
|
59
69
|
await this.#connection.write(await this.encrypt(data));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import { type TransportProvider } from "./1_transport_provider.js";
|
|
21
|
+
export declare function transportProviderMtproxy(link: string): TransportProvider;
|
|
22
|
+
export declare function transportProviderMtproxy(hostname: string, port: number, secret: Uint8Array<ArrayBuffer>): TransportProvider;
|
|
23
|
+
//# sourceMappingURL=2_transport_provider_mtproxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2_transport_provider_mtproxy.d.ts","sourceRoot":"","sources":["../../src/transport/2_transport_provider_mtproxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAW,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;AAC1E,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
5
|
+
*
|
|
6
|
+
* This file is part of MTKruto.
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.transportProviderMtproxy = transportProviderMtproxy;
|
|
23
|
+
const _0_deps_js_1 = require("../0_deps.js");
|
|
24
|
+
const _1_connection_tcp_js_1 = require("../connection/1_connection_tcp.js");
|
|
25
|
+
const _1_connection_tls_js_1 = require("../connection/1_connection_tls.js");
|
|
26
|
+
const _1_transport_intermediate_js_1 = require("./1_transport_intermediate.js");
|
|
27
|
+
const _1_transport_provider_js_1 = require("./1_transport_provider.js");
|
|
28
|
+
function transportProviderMtproxy(hostnameOrLink, port, secret) {
|
|
29
|
+
let hostname = hostnameOrLink;
|
|
30
|
+
if (port === undefined && secret === undefined) {
|
|
31
|
+
const url = new URL(hostnameOrLink);
|
|
32
|
+
const hostname_ = url.searchParams.get("server");
|
|
33
|
+
const port_ = url.searchParams.get("port");
|
|
34
|
+
const secret_ = url.searchParams.get("secret");
|
|
35
|
+
if (!hostname_ || !port_ || !secret_) {
|
|
36
|
+
throw new TypeError("Invalid MTProxy link.");
|
|
37
|
+
}
|
|
38
|
+
hostname = hostname_;
|
|
39
|
+
port = parseInt(port_);
|
|
40
|
+
secret = (0, _0_deps_js_1.decodeHex)(secret_);
|
|
41
|
+
if (isNaN(port) || port < 0 || port > 0xFFFF) {
|
|
42
|
+
throw new TypeError("Server port is invalid.");
|
|
43
|
+
}
|
|
44
|
+
if (secret.byteLength < 16) {
|
|
45
|
+
throw new TypeError("Proxy secret must be at least 16 bytes.");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return ({ dc, isCdn }) => {
|
|
49
|
+
const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
|
|
50
|
+
const connection = secret.byteLength <= 17 ? new _1_connection_tcp_js_1.ConnectionTCP(hostname, port) : new _1_connection_tls_js_1.ConnectionTLS(hostname, port, secret);
|
|
51
|
+
const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, { isPadded: true, isObfuscated: true, secret, dcId });
|
|
52
|
+
return { connection, transport, dcId };
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -39,8 +39,8 @@ const transportProviderWebSocket = (params) => {
|
|
|
39
39
|
params.wss ??= typeof location !== "undefined" && location.protocol === "http:" && location.hostname !== "localhost" ? false : true;
|
|
40
40
|
const url = `${params.wss ? "wss" : "ws"}://${dcToNameMap[dc]}${isCdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
41
41
|
const connection = new _2_connection_js_1.ConnectionWebSocket(url);
|
|
42
|
-
const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, true);
|
|
43
42
|
const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
|
|
43
|
+
const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, { isObfuscated: true, dcId });
|
|
44
44
|
return { connection, transport, dcId };
|
|
45
45
|
};
|
|
46
46
|
};
|
|
@@ -27,4 +27,5 @@ export declare class CTR {
|
|
|
27
27
|
static importKey(key: Uint8Array<ArrayBuffer>): Promise<CryptoKey>;
|
|
28
28
|
call(data: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>>;
|
|
29
29
|
}
|
|
30
|
+
export declare function hmacSha256(data: Uint8Array<ArrayBuffer>, secret: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>>;
|
|
30
31
|
//# sourceMappingURL=1_crypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_crypto.d.ts","sourceRoot":"","sources":["../../src/utilities/1_crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,qBAAa,GAAG;;IAMd,IAAI,MAAM,IAAI;QAAE,EAAE,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAE9C;gBAEW,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU;WAK7B,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAIlE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;CAkD5E"}
|
|
1
|
+
{"version":3,"file":"1_crypto.d.ts","sourceRoot":"","sources":["../../src/utilities/1_crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,qBAAa,GAAG;;IAMd,IAAI,MAAM,IAAI;QAAE,EAAE,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAE9C;gBAEW,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU;WAK7B,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAIlE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;CAkD5E;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,oCAe9F"}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.CTR = void 0;
|
|
23
|
+
exports.hmacSha256 = hmacSha256;
|
|
23
24
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
24
25
|
const _0_int_js_1 = require("./0_int.js");
|
|
25
26
|
class CTR {
|
|
@@ -81,3 +82,7 @@ class CTR {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
exports.CTR = CTR;
|
|
85
|
+
async function hmacSha256(data, secret) {
|
|
86
|
+
const key = await crypto.subtle.importKey("raw", secret, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
87
|
+
return new Uint8Array(await crypto.subtle.sign("HMAC", key, data.buffer));
|
|
88
|
+
}
|
|
@@ -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
|
-
}
|