@hugoalh/adler32 0.5.1 → 0.6.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/README.md +29 -20
- package/cli.d.ts +3 -0
- package/cli.d.ts.map +1 -0
- package/cli.js +117 -0
- package/mod.d.ts.map +1 -1
- package/mod.js +4 -3
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -22,28 +22,15 @@ Any runtime which support ECMAScript should able to use this; These runtimes are
|
|
|
22
22
|
|
|
23
23
|
This does not request any runtime permission.
|
|
24
24
|
|
|
25
|
-
## #️⃣
|
|
25
|
+
## #️⃣ Entrypoints
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- JSR
|
|
32
|
-
```
|
|
33
|
-
jsr:@hugoalh/adler32[@{Tag}]
|
|
34
|
-
```
|
|
35
|
-
- NPM
|
|
36
|
-
```
|
|
37
|
-
npm:@hugoalh/adler32[@{Tag}]
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
| **Name** | **Path** | **Description** |
|
|
41
|
-
|:--|:--|:--|
|
|
42
|
-
| `.` | `./mod.ts` | Default. |
|
|
27
|
+
| **Type** | **Name** | **Path** | **Description** |
|
|
28
|
+
|:--|:--|:--|:--|
|
|
29
|
+
| API | `.` | `./mod.ts` | Default. |
|
|
30
|
+
| CLI | `./cli` | `./cli.ts` | Default. |
|
|
43
31
|
|
|
44
32
|
> [!NOTE]
|
|
45
|
-
> - Different runtimes have vary support for the
|
|
46
|
-
> - It is recommended to include tag for immutability.
|
|
33
|
+
> - Different runtimes have vary support for the entrypoints, visit the runtime documentation for more information.
|
|
47
34
|
> - These are not part of the public APIs hence should not be used:
|
|
48
35
|
> - Benchmark/Test file (e.g.: `example.bench.ts`, `example.test.ts`).
|
|
49
36
|
> - Entrypoint name or path include any underscore prefix (e.g.: `_example.ts`, `foo/_example.ts`).
|
|
@@ -73,12 +60,34 @@ This does not request any runtime permission.
|
|
|
73
60
|
|
|
74
61
|
> [!NOTE]
|
|
75
62
|
> - For the full or prettier documentation, can visit via:
|
|
76
|
-
> - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/doc
|
|
63
|
+
> - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/doc)
|
|
77
64
|
> - [JSR](https://jsr.io/@hugoalh/adler32)
|
|
78
65
|
|
|
66
|
+
## 🧩 CLIs
|
|
67
|
+
|
|
68
|
+
- ```powershell
|
|
69
|
+
adler32 $Context
|
|
70
|
+
```
|
|
71
|
+
- ```powershell
|
|
72
|
+
adler32 --file $FilePath
|
|
73
|
+
<# 🔀 Unordered Positions: `--file`, `$FilePath` #>
|
|
74
|
+
```
|
|
75
|
+
| **Argument** | **Type** | **Description** |
|
|
76
|
+
|:--|:--|:--|
|
|
77
|
+
| `file` | `switch` | Whether the resource is from file. |
|
|
78
|
+
- ```powershell
|
|
79
|
+
adler32 --stdin
|
|
80
|
+
```
|
|
81
|
+
| **Argument** | **Type** | **Description** |
|
|
82
|
+
|:--|:--|:--|
|
|
83
|
+
| `stdin` | `switch` | Whether the resource is from standard stream input. |
|
|
84
|
+
|
|
79
85
|
## ✍️ Examples
|
|
80
86
|
|
|
81
87
|
- ```ts
|
|
82
88
|
new Adler32("Wikipedia").hashHex();
|
|
83
89
|
//=> "11E60398"
|
|
84
90
|
```
|
|
91
|
+
- ```powershell
|
|
92
|
+
adler32 'Wikipedia'
|
|
93
|
+
```
|
package/cli.d.ts
ADDED
package/cli.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["src/cli.ts"],"names":[],"mappings":""}
|
package/cli.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
3
|
+
if (value !== null && value !== void 0) {
|
|
4
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
5
|
+
var dispose, inner;
|
|
6
|
+
if (async) {
|
|
7
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
8
|
+
dispose = value[Symbol.asyncDispose];
|
|
9
|
+
}
|
|
10
|
+
if (dispose === void 0) {
|
|
11
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
12
|
+
dispose = value[Symbol.dispose];
|
|
13
|
+
if (async) inner = dispose;
|
|
14
|
+
}
|
|
15
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
16
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
17
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
18
|
+
}
|
|
19
|
+
else if (async) {
|
|
20
|
+
env.stack.push({ async: true });
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
25
|
+
return function (env) {
|
|
26
|
+
function fail(e) {
|
|
27
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
28
|
+
env.hasError = true;
|
|
29
|
+
}
|
|
30
|
+
var r, s = 0;
|
|
31
|
+
function next() {
|
|
32
|
+
while (r = env.stack.pop()) {
|
|
33
|
+
try {
|
|
34
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
35
|
+
if (r.dispose) {
|
|
36
|
+
var result = r.dispose.call(r.value);
|
|
37
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
38
|
+
}
|
|
39
|
+
else s |= 1;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
fail(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
46
|
+
if (env.hasError) throw env.error;
|
|
47
|
+
}
|
|
48
|
+
return next();
|
|
49
|
+
};
|
|
50
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
51
|
+
var e = new Error(message);
|
|
52
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
53
|
+
});
|
|
54
|
+
import { constants as fsConstants, open as openFile } from "node:fs/promises";
|
|
55
|
+
import { exit, stdin } from "node:process";
|
|
56
|
+
import { parseArgs, styleText } from "node:util";
|
|
57
|
+
import { Adler32 } from "./mod.js";
|
|
58
|
+
if (!import.meta.main) {
|
|
59
|
+
throw new Error(`This entrypoint is for command line only!`);
|
|
60
|
+
}
|
|
61
|
+
addEventListener("unhandledrejection", (event) => {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
let message;
|
|
64
|
+
if (event.reason instanceof Error) {
|
|
65
|
+
message = event.reason.message;
|
|
66
|
+
if ((event.reason.stack ?? "").length > 0) {
|
|
67
|
+
message += `\n${event.reason.stack}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
message = String(event.reason);
|
|
72
|
+
}
|
|
73
|
+
console.error(`${styleText(["red"], "ERROR", { validateStream: false })}\t${message}`);
|
|
74
|
+
exit(1);
|
|
75
|
+
}, { capture: true });
|
|
76
|
+
const { positionals, values: { file: fromFile = false, stdin: fromStdin = false } } = parseArgs({
|
|
77
|
+
allowPositionals: true,
|
|
78
|
+
options: {
|
|
79
|
+
file: {
|
|
80
|
+
type: "boolean"
|
|
81
|
+
},
|
|
82
|
+
stdin: {
|
|
83
|
+
type: "boolean"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (fromFile && fromStdin) {
|
|
88
|
+
throw new SyntaxError(`Unable to request resource from file and stdin together!`);
|
|
89
|
+
}
|
|
90
|
+
const expectArgumentsLength = fromStdin ? 0 : 1;
|
|
91
|
+
if (positionals.length !== expectArgumentsLength) {
|
|
92
|
+
throw new SyntaxError(`Invalid arguments length! Expect: ${expectArgumentsLength}, Current: ${positionals.length}.`);
|
|
93
|
+
}
|
|
94
|
+
const instance = new Adler32();
|
|
95
|
+
if (fromFile) {
|
|
96
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
97
|
+
try {
|
|
98
|
+
const file = __addDisposableResource(env_1, await openFile(positionals[0], fsConstants.O_RDONLY), true);
|
|
99
|
+
await instance.updateFromStream(file.readableWebStream());
|
|
100
|
+
}
|
|
101
|
+
catch (e_1) {
|
|
102
|
+
env_1.error = e_1;
|
|
103
|
+
env_1.hasError = true;
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
const result_1 = __disposeResources(env_1);
|
|
107
|
+
if (result_1)
|
|
108
|
+
await result_1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if (fromStdin) {
|
|
112
|
+
await instance.updateFromStream(stdin);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
instance.update(positionals[0]);
|
|
116
|
+
}
|
|
117
|
+
console.log(instance.hashHex());
|
package/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["src/mod.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAC9B,MAAM,GACN,cAAc,GACd,UAAU,GACV,WAAW,GACX,WAAW,CAAC;AACf;;GAEG;AACH,qBAAa,OAAO;;IACnB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAMD;;;OAGG;gBACS,IAAI,CAAC,EAAE,qBAAqB;IAKxC;;;OAGG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IACD;;;OAGG;IACH,MAAM,IAAI,IAAI;IAId;;;OAGG;IACH,IAAI,IAAI,UAAU;IAIlB;;;OAGG;IACH,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["src/mod.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAC9B,MAAM,GACN,cAAc,GACd,UAAU,GACV,WAAW,GACX,WAAW,CAAC;AACf;;GAEG;AACH,qBAAa,OAAO;;IACnB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAMD;;;OAGG;gBACS,IAAI,CAAC,EAAE,qBAAqB;IAKxC;;;OAGG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IACD;;;OAGG;IACH,MAAM,IAAI,IAAI;IAId;;;OAGG;IACH,IAAI,IAAI,UAAU;IAIlB;;;OAGG;IACH,OAAO,IAAI,MAAM;IAUjB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAazC;;;;OAIG;IACG,gBAAgB,CAAC,MAAM,EAAE,cAAc,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAMpF;AACD,eAAe,OAAO,CAAC"}
|
package/mod.js
CHANGED
|
@@ -52,10 +52,11 @@ export class Adler32 {
|
|
|
52
52
|
*/
|
|
53
53
|
hashHex() {
|
|
54
54
|
if (this.#hashHex === null) {
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
throw new Error(`Unexpected hash hex result \`${
|
|
55
|
+
const result = (this.#b * 65536n + this.#a).toString(16).toUpperCase().padStart(8, "0");
|
|
56
|
+
if (result.length !== 8) {
|
|
57
|
+
throw new Error(`Unexpected hash hex result \`${result}\`! Please submit a bug report.`);
|
|
58
58
|
}
|
|
59
|
+
this.#hashHex = result;
|
|
59
60
|
}
|
|
60
61
|
return this.#hashHex;
|
|
61
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hugoalh/adler32",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A module to get the checksum of the data with algorithm Adler32.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adler32",
|
|
@@ -13,9 +13,18 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "hugoalh",
|
|
15
15
|
"type": "module",
|
|
16
|
+
"bin": {
|
|
17
|
+
"adler32": "./cli.js"
|
|
18
|
+
},
|
|
16
19
|
"main": "./mod.js",
|
|
17
20
|
"module": "./mod.js",
|
|
18
21
|
"exports": {
|
|
22
|
+
"./cli": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./cli.d.ts",
|
|
25
|
+
"default": "./cli.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
19
28
|
".": {
|
|
20
29
|
"import": {
|
|
21
30
|
"types": "./mod.d.ts",
|
|
@@ -31,12 +40,8 @@
|
|
|
31
40
|
"dependencies": {
|
|
32
41
|
"es-arraybuffer-base64": "^1.1.2"
|
|
33
42
|
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@types/node": "^24.5.0"
|
|
36
|
-
},
|
|
37
43
|
"private": false,
|
|
38
44
|
"publishConfig": {
|
|
39
45
|
"access": "public"
|
|
40
|
-
}
|
|
41
|
-
"_generatedBy": "dnt@dev"
|
|
46
|
+
}
|
|
42
47
|
}
|