@hugoalh/adler32 0.1.0 → 0.2.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/LICENSE.md +1 -1
- package/README.md +5 -3
- package/cli.d.ts.map +1 -1
- package/cli.js +20 -22
- package/deps/jsr.io/@std/cli/{1.0.6 → 1.0.9}/parse_args.d.ts +11 -7
- package/deps/jsr.io/@std/cli/{1.0.6 → 1.0.9}/parse_args.d.ts.map +1 -1
- package/mod.d.ts +17 -1
- package/mod.d.ts.map +1 -1
- package/mod.js +91 -6
- package/package.json +7 -1
- /package/deps/jsr.io/@std/cli/{1.0.6 → 1.0.9}/parse_args.js +0 -0
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright © 2024 hugoalh
|
|
3
|
+
Copyright © 2024\~2025 hugoalh
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -48,9 +48,10 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
|
|
|
48
48
|
> - For usage of JSR or NPM resources, it is recommended to import the entire module with the main entrypoint, however it is also able to import part of the module with sub entrypoint if available, please visit the [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub entrypoints.
|
|
49
49
|
> - It is recommended to use this module with tag for immutability.
|
|
50
50
|
|
|
51
|
-
### 🛡️
|
|
51
|
+
### 🛡️ Runtime Permissions
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
- File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
|
|
54
|
+
- *Resources* (Optional)
|
|
54
55
|
|
|
55
56
|
## 🧩 APIs
|
|
56
57
|
|
|
@@ -67,10 +68,11 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
|
|
|
67
68
|
update(data: Adler32AcceptDataType): this;
|
|
68
69
|
static fromFile(filePath: string | URL): Promise<Adler32>;
|
|
69
70
|
static fromFileSync(filePath: string | URL): Adler32;
|
|
71
|
+
static fromStream(stream: ReadableStream<Adler32AcceptDataType>): Promise<Adler32>;
|
|
70
72
|
}
|
|
71
73
|
```
|
|
72
74
|
- ```ts
|
|
73
|
-
type Adler32AcceptDataType = string |
|
|
75
|
+
type Adler32AcceptDataType = string | BigUint64Array | Uint8Array | Uint16Array | Uint32Array;
|
|
74
76
|
```
|
|
75
77
|
|
|
76
78
|
> [!NOTE]
|
package/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC"}
|
package/cli.js
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "./_dnt.polyfills.js";
|
|
3
3
|
import * as dntShim from "./_dnt.shims.js";
|
|
4
|
-
import { parseArgs } from "./deps/jsr.io/@std/cli/1.0.
|
|
4
|
+
import { parseArgs } from "./deps/jsr.io/@std/cli/1.0.9/parse_args.js";
|
|
5
5
|
import { Adler32 } from "./mod.js";
|
|
6
6
|
if (!(import.meta.url === ("file:///" + process.argv[1].replace(/\\/g, "/")).replace(/\/{3,}/, "///"))) {
|
|
7
7
|
throw new Error(`This script is for command line usage only!`);
|
|
8
8
|
}
|
|
9
9
|
const args = parseArgs(dntShim.Deno.args, {
|
|
10
|
-
boolean: [
|
|
10
|
+
boolean: [
|
|
11
|
+
"file",
|
|
12
|
+
"stdin"
|
|
13
|
+
]
|
|
11
14
|
});
|
|
12
15
|
const fromFile = args.file;
|
|
13
16
|
const fromStdin = args.stdin;
|
|
14
|
-
const
|
|
17
|
+
const argsValues = args._.map((value) => {
|
|
15
18
|
return String(value);
|
|
16
19
|
});
|
|
17
20
|
if (fromFile && fromStdin) {
|
|
18
21
|
throw new SyntaxError(`Unable to use the sources of file and stdin together!`);
|
|
19
22
|
}
|
|
20
23
|
if (fromFile) {
|
|
21
|
-
if (
|
|
24
|
+
if (argsValues.length === 0) {
|
|
22
25
|
throw new SyntaxError(`File path is not defined!`);
|
|
23
26
|
}
|
|
24
|
-
if (
|
|
25
|
-
throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${
|
|
27
|
+
if (argsValues.length !== 1) {
|
|
28
|
+
throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
|
|
26
29
|
}
|
|
27
|
-
console.log((await Adler32.fromFile(
|
|
30
|
+
console.log((await Adler32.fromFile(argsValues[0])).hashHexPadding());
|
|
28
31
|
}
|
|
29
32
|
else if (fromStdin) {
|
|
30
|
-
if (
|
|
31
|
-
throw new SyntaxError(`Too many arguments! Expect: 0; Current: ${
|
|
33
|
+
if (argsValues.length !== 0) {
|
|
34
|
+
throw new SyntaxError(`Too many arguments! Expect: 0; Current: ${argsValues.length}.`);
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
const { done, value } = await stdinReader.read();
|
|
37
|
-
if (done) {
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
instance.update(value);
|
|
36
|
+
let data = Uint8Array.from([]);
|
|
37
|
+
for await (const chunk of dntShim.Deno.stdin.readable) {
|
|
38
|
+
data = Uint8Array.from([...data, ...chunk]);
|
|
41
39
|
}
|
|
42
|
-
console.log(
|
|
40
|
+
console.log(new Adler32(new TextDecoder().decode(data).replace(/\r?\n$/, "")).hashHexPadding());
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
|
-
if (
|
|
43
|
+
if (argsValues.length === 0) {
|
|
46
44
|
throw new SyntaxError(`Data is not defined!`);
|
|
47
45
|
}
|
|
48
|
-
if (
|
|
49
|
-
throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${
|
|
46
|
+
if (argsValues.length !== 1) {
|
|
47
|
+
throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
|
|
50
48
|
}
|
|
51
|
-
console.log(new Adler32(
|
|
49
|
+
console.log(new Adler32(argsValues[0]).hashHexPadding());
|
|
52
50
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Command line arguments parser based on
|
|
3
3
|
* {@link https://github.com/minimistjs/minimist | minimist}.
|
|
4
4
|
*
|
|
5
|
-
* @example
|
|
5
|
+
* @example Usage
|
|
6
6
|
* ```ts
|
|
7
7
|
* import { parseArgs } from "@std/cli/parse-args";
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* const args = parseArgs(Deno.args);
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
12
|
* @module
|
|
@@ -102,14 +102,18 @@ export interface ParseOptions<TBooleans extends BooleanType = BooleanType, TStri
|
|
|
102
102
|
*
|
|
103
103
|
* @default {false}
|
|
104
104
|
*
|
|
105
|
-
*
|
|
105
|
+
* @example Double dash option is false
|
|
106
|
+
* ```ts
|
|
107
|
+
* // $ deno run example.ts -- a arg1
|
|
108
|
+
* import { parseArgs } from "@std/cli/parse-args";
|
|
109
|
+
* const args = parseArgs(Deno.args, { "--": false }); // args equals { _: [ "a", "arg1" ] }
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example Double dash option is true
|
|
106
113
|
* ```ts
|
|
107
114
|
* // $ deno run example.ts -- a arg1
|
|
108
115
|
* import { parseArgs } from "@std/cli/parse-args";
|
|
109
|
-
*
|
|
110
|
-
* // output: { _: [ "a", "arg1" ] }
|
|
111
|
-
* console.dir(parseArgs(Deno.args, { "--": true }));
|
|
112
|
-
* // output: { _: [], --: [ "a", "arg1" ] }
|
|
116
|
+
* const args = parseArgs(Deno.args, { "--": true }); // args equals { _: [], --: [ "a", "arg1" ] }
|
|
113
117
|
* ```
|
|
114
118
|
*/
|
|
115
119
|
"--"?: TDoubleDash;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse_args.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cli/1.0.
|
|
1
|
+
{"version":3,"file":"parse_args.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cli/1.0.9/parse_args.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,KAAK,EAAE,CAAC,OAAO,IAAI,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACtD,OAAO,SAAS,MAAM,cAAc,GAClC;KAAG,GAAG,IAAI,MAAM,cAAc,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;CAAE,GAC5D,KAAK,GACL,OAAO,CAAC;AAEZ;;GAEG;AACH,KAAK,mBAAmB,CAAC,MAAM,IAC7B,CAAC,MAAM,SAAS,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,KAAK,CAAC,SAC1D,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,OAAO,GAAG,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,GACxE,KAAK,CAAC;AAEZ,gBAAgB;AAChB,KAAK,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAChD,gBAAgB;AAChB,KAAK,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;AACrC,gBAAgB;AAChB,KAAK,OAAO,GAAG,UAAU,GAAG,WAAW,CAAC;AAExC,gBAAgB;AAChB,KAAK,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;AACtC,gBAAgB;AAChB,KAAK,S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IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;CACnE;AAyED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,SAAS,CACvB,KAAK,SAAS,MAAM,CAClB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,SAAS,EACT,QAAQ,CACT,EACD,WAAW,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EACnD,SAAS,SAAS,WAAW,GAAG,SAAS,EACzC,QAAQ,SAAS,UAAU,GAAG,SAAS,EACvC,YAAY,SAAS,WAAW,GAAG,SAAS,EAC5C,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,SAAS,EACjE,QAAQ,SAAS,OAAO,CAAC,cAAc,EAAE,WAAW,CAAC,GAAG,SAAS,GAAG,SAAS,EAC7E,cAAc,SAAS,MAAM,GAAG,MAAM,EACtC,WAAW,SAAS,MAAM,GAAG,MAAM,EAEnC,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE,YAAY,CACpB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,SAAS,EACT,QAAQ,EACR,WAAW,CACZ,GACA,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAwQ1B"}
|
package/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./_dnt.polyfills.js";
|
|
2
|
-
export type Adler32AcceptDataType = string |
|
|
2
|
+
export type Adler32AcceptDataType = string | BigUint64Array | Uint8Array | Uint16Array | Uint32Array;
|
|
3
3
|
/**
|
|
4
4
|
* Get the checksum of the data with algorithm Adler32.
|
|
5
5
|
*/
|
|
@@ -53,16 +53,32 @@ export declare class Adler32 {
|
|
|
53
53
|
update(data: Adler32AcceptDataType): this;
|
|
54
54
|
/**
|
|
55
55
|
* Initialize from file, asynchronously.
|
|
56
|
+
*
|
|
57
|
+
* > **🛡️ Runtime Permissions**
|
|
58
|
+
* >
|
|
59
|
+
* > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
|
|
60
|
+
* > - *Resources*
|
|
56
61
|
* @param {string | URL} filePath Path of the file.
|
|
57
62
|
* @returns {Promise<Adler32>}
|
|
58
63
|
*/
|
|
59
64
|
static fromFile(filePath: string | URL): Promise<Adler32>;
|
|
60
65
|
/**
|
|
61
66
|
* Initialize from file, synchronously.
|
|
67
|
+
*
|
|
68
|
+
* > **🛡️ Runtime Permissions**
|
|
69
|
+
* >
|
|
70
|
+
* > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
|
|
71
|
+
* > - *Resources*
|
|
62
72
|
* @param {string | URL} filePath Path of the file.
|
|
63
73
|
* @returns {Adler32}
|
|
64
74
|
*/
|
|
65
75
|
static fromFileSync(filePath: string | URL): Adler32;
|
|
76
|
+
/**
|
|
77
|
+
* Initialize from readable stream, asynchronously.
|
|
78
|
+
* @param {ReadableStream<Adler32AcceptDataType>} stream Readable stream.
|
|
79
|
+
* @returns {Promise<Adler32>}
|
|
80
|
+
*/
|
|
81
|
+
static fromStream(stream: ReadableStream<Adler32AcceptDataType>): Promise<Adler32>;
|
|
66
82
|
}
|
|
67
83
|
export default Adler32;
|
|
68
84
|
//# sourceMappingURL=mod.d.ts.map
|
package/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,cAAc,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AACrG;;GAEG;AACH,qBAAa,OAAO;;IAInB;;;OAGG;gBACS,IAAI,CAAC,EAAE,qBAAqB;IAKxC;;;OAGG;IACH,IAAI,IAAI,MAAM;IAMd;;;OAGG;IACH,UAAU,IAAI,MAAM;IAGpB;;;OAGG;IACH,aAAa,IAAI,MAAM;IAGvB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAGpB;;;OAGG;IACH,OAAO,IAAI,MAAM;IAGjB;;;OAGG;IACH,cAAc,IAAI,MAAM;IAGxB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAGpB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAQzC;;;;;;;;;OASG;WACU,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAI/D;;;;;;;;;OASG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO;IAGpD;;;;OAIG;WACU,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAOxF;AACD,eAAe,OAAO,CAAC"}
|
package/mod.js
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
import "./_dnt.polyfills.js";
|
|
2
2
|
import * as dntShim from "./_dnt.shims.js";
|
|
3
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
4
|
+
if (value !== null && value !== void 0) {
|
|
5
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
6
|
+
var dispose, inner;
|
|
7
|
+
if (async) {
|
|
8
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
9
|
+
dispose = value[Symbol.asyncDispose];
|
|
10
|
+
}
|
|
11
|
+
if (dispose === void 0) {
|
|
12
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
13
|
+
dispose = value[Symbol.dispose];
|
|
14
|
+
if (async) inner = dispose;
|
|
15
|
+
}
|
|
16
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
17
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
18
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
19
|
+
}
|
|
20
|
+
else if (async) {
|
|
21
|
+
env.stack.push({ async: true });
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
26
|
+
return function (env) {
|
|
27
|
+
function fail(e) {
|
|
28
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
29
|
+
env.hasError = true;
|
|
30
|
+
}
|
|
31
|
+
var r, s = 0;
|
|
32
|
+
function next() {
|
|
33
|
+
while (r = env.stack.pop()) {
|
|
34
|
+
try {
|
|
35
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
36
|
+
if (r.dispose) {
|
|
37
|
+
var result = r.dispose.call(r.value);
|
|
38
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
39
|
+
}
|
|
40
|
+
else s |= 1;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
fail(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
47
|
+
if (env.hasError) throw env.error;
|
|
48
|
+
}
|
|
49
|
+
return next();
|
|
50
|
+
};
|
|
51
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
52
|
+
var e = new Error(message);
|
|
53
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
54
|
+
});
|
|
3
55
|
/**
|
|
4
56
|
* Get the checksum of the data with algorithm Adler32.
|
|
5
57
|
*/
|
|
@@ -22,7 +74,7 @@ export class Adler32 {
|
|
|
22
74
|
*/
|
|
23
75
|
hash() {
|
|
24
76
|
if (this.#hash === null) {
|
|
25
|
-
this.#hash =
|
|
77
|
+
this.#hash = this.#b * 65536n + this.#a;
|
|
26
78
|
}
|
|
27
79
|
return this.#hash;
|
|
28
80
|
}
|
|
@@ -75,27 +127,60 @@ export class Adler32 {
|
|
|
75
127
|
*/
|
|
76
128
|
update(data) {
|
|
77
129
|
this.#hash = null;
|
|
78
|
-
for (const byte of
|
|
79
|
-
this.#a
|
|
80
|
-
this.#b
|
|
130
|
+
for (const byte of ((typeof data === "string") ? new TextEncoder().encode(data) : data)) {
|
|
131
|
+
this.#a = (this.#a + BigInt(byte)) % 65521n;
|
|
132
|
+
this.#b = (this.#b + this.#a) % 65521n;
|
|
81
133
|
}
|
|
82
134
|
return this;
|
|
83
135
|
}
|
|
84
136
|
/**
|
|
85
137
|
* Initialize from file, asynchronously.
|
|
138
|
+
*
|
|
139
|
+
* > **🛡️ Runtime Permissions**
|
|
140
|
+
* >
|
|
141
|
+
* > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
|
|
142
|
+
* > - *Resources*
|
|
86
143
|
* @param {string | URL} filePath Path of the file.
|
|
87
144
|
* @returns {Promise<Adler32>}
|
|
88
145
|
*/
|
|
89
146
|
static async fromFile(filePath) {
|
|
90
|
-
|
|
147
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
148
|
+
try {
|
|
149
|
+
const file = __addDisposableResource(env_1, await dntShim.Deno.open(filePath), false);
|
|
150
|
+
return await Adler32.fromStream(file.readable);
|
|
151
|
+
}
|
|
152
|
+
catch (e_1) {
|
|
153
|
+
env_1.error = e_1;
|
|
154
|
+
env_1.hasError = true;
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
__disposeResources(env_1);
|
|
158
|
+
}
|
|
91
159
|
}
|
|
92
160
|
/**
|
|
93
161
|
* Initialize from file, synchronously.
|
|
162
|
+
*
|
|
163
|
+
* > **🛡️ Runtime Permissions**
|
|
164
|
+
* >
|
|
165
|
+
* > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
|
|
166
|
+
* > - *Resources*
|
|
94
167
|
* @param {string | URL} filePath Path of the file.
|
|
95
168
|
* @returns {Adler32}
|
|
96
169
|
*/
|
|
97
170
|
static fromFileSync(filePath) {
|
|
98
|
-
return new
|
|
171
|
+
return new this(dntShim.Deno.readFileSync(filePath));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Initialize from readable stream, asynchronously.
|
|
175
|
+
* @param {ReadableStream<Adler32AcceptDataType>} stream Readable stream.
|
|
176
|
+
* @returns {Promise<Adler32>}
|
|
177
|
+
*/
|
|
178
|
+
static async fromStream(stream) {
|
|
179
|
+
const instance = new Adler32();
|
|
180
|
+
for await (const chunk of stream) {
|
|
181
|
+
instance.update(chunk);
|
|
182
|
+
}
|
|
183
|
+
return instance;
|
|
99
184
|
}
|
|
100
185
|
}
|
|
101
186
|
export default Adler32;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hugoalh/adler32",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A CLI and module to get the checksum of the data with algorithm Adler32.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adler32"
|
|
@@ -18,6 +18,12 @@
|
|
|
18
18
|
"main": "./mod.js",
|
|
19
19
|
"module": "./mod.js",
|
|
20
20
|
"exports": {
|
|
21
|
+
"./cli": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./cli.d.ts",
|
|
24
|
+
"default": "./cli.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
21
27
|
".": {
|
|
22
28
|
"import": {
|
|
23
29
|
"types": "./mod.d.ts",
|
|
File without changes
|