@thi.ng/bencode 2.1.122 → 2.1.123
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/CHANGELOG.md +7 -1
- package/README.md +3 -2
- package/decode.js +12 -12
- package/encode.js +5 -5
- package/package.json +13 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [2.1.123](https://github.com/thi-ng/umbrella/tree/@thi.ng/bencode@2.1.123) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
### [2.1.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/bencode@2.1.6) (2022-04-07)
|
|
13
19
|
|
|
14
20
|
#### 🩹 Bug fixes
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -86,7 +86,7 @@ For Node.js REPL:
|
|
|
86
86
|
const bc = await import("@thi.ng/bencode");
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 1.
|
|
89
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.18 KB
|
|
90
90
|
|
|
91
91
|
## Dependencies
|
|
92
92
|
|
|
@@ -94,6 +94,7 @@ Package sizes (brotli'd, pre-treeshake): ESM: 1.17 KB
|
|
|
94
94
|
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
95
95
|
- [@thi.ng/defmulti](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti)
|
|
96
96
|
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
97
|
+
- [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
|
|
97
98
|
- [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
|
|
98
99
|
- [@thi.ng/transducers-binary](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers-binary)
|
|
99
100
|
|
package/decode.js
CHANGED
|
@@ -34,21 +34,21 @@ const decode = (buf, utf8 = true) => {
|
|
|
34
34
|
x = i.value;
|
|
35
35
|
switch (x) {
|
|
36
36
|
case 100 /* DICT */:
|
|
37
|
-
|
|
37
|
+
__ensureNotKey(stack, "dict");
|
|
38
38
|
stack.push({ type: 4 /* DICT */, val: {} });
|
|
39
39
|
break;
|
|
40
40
|
case 108 /* LIST */:
|
|
41
|
-
|
|
41
|
+
__ensureNotKey(stack, "list");
|
|
42
42
|
stack.push({ type: 5 /* LIST */, val: [] });
|
|
43
43
|
break;
|
|
44
44
|
case 105 /* INT */:
|
|
45
|
-
x =
|
|
45
|
+
x = __collect(stack, __readInt(iter, 0));
|
|
46
46
|
if (x !== void 0) {
|
|
47
47
|
return x;
|
|
48
48
|
}
|
|
49
49
|
break;
|
|
50
50
|
case 102 /* FLOAT */:
|
|
51
|
-
x =
|
|
51
|
+
x = __collect(stack, __readFloat(iter));
|
|
52
52
|
if (x !== void 0) {
|
|
53
53
|
return x;
|
|
54
54
|
}
|
|
@@ -73,11 +73,11 @@ const decode = (buf, utf8 = true) => {
|
|
|
73
73
|
break;
|
|
74
74
|
default:
|
|
75
75
|
if (x >= 48 /* ZERO */ && x <= 57 /* NINE */) {
|
|
76
|
-
x =
|
|
76
|
+
x = __readBytes(
|
|
77
77
|
iter,
|
|
78
|
-
|
|
78
|
+
__readInt(iter, x - 48 /* ZERO */, 58 /* COLON */)
|
|
79
79
|
);
|
|
80
|
-
x =
|
|
80
|
+
x = __collect(stack, x, utf8);
|
|
81
81
|
if (x !== void 0) {
|
|
82
82
|
return x;
|
|
83
83
|
}
|
|
@@ -90,14 +90,14 @@ const decode = (buf, utf8 = true) => {
|
|
|
90
90
|
}
|
|
91
91
|
return peek(stack).val;
|
|
92
92
|
};
|
|
93
|
-
const
|
|
93
|
+
const __ensureNotKey = (stack, type) => {
|
|
94
94
|
const x = peek(stack);
|
|
95
95
|
assert(
|
|
96
96
|
!x || x.type !== 4 /* DICT */ || x.key,
|
|
97
97
|
type + " not supported as dict key"
|
|
98
98
|
);
|
|
99
99
|
};
|
|
100
|
-
const
|
|
100
|
+
const __collect = (stack, x, utf8 = false) => {
|
|
101
101
|
const parent = peek(stack);
|
|
102
102
|
if (!parent) return x;
|
|
103
103
|
if (parent.type === 5 /* LIST */) {
|
|
@@ -111,7 +111,7 @@ const collect = (stack, x, utf8 = false) => {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
|
-
const
|
|
114
|
+
const __readInt = (iter, acc, end = 101 /* END */) => {
|
|
115
115
|
let i;
|
|
116
116
|
let x;
|
|
117
117
|
let isSigned = false;
|
|
@@ -130,7 +130,7 @@ const readInt = (iter, acc, end = 101 /* END */) => {
|
|
|
130
130
|
}
|
|
131
131
|
illegalState(`incomplete int`);
|
|
132
132
|
};
|
|
133
|
-
const
|
|
133
|
+
const __readFloat = (iter) => {
|
|
134
134
|
let i;
|
|
135
135
|
let x;
|
|
136
136
|
let acc = "";
|
|
@@ -146,7 +146,7 @@ const readFloat = (iter) => {
|
|
|
146
146
|
}
|
|
147
147
|
illegalState(`incomplete float`);
|
|
148
148
|
};
|
|
149
|
-
const
|
|
149
|
+
const __readBytes = (iter, len) => {
|
|
150
150
|
let i;
|
|
151
151
|
let buf = [];
|
|
152
152
|
while (len-- > 0 && !(i = iter.next()).done) {
|
package/encode.js
CHANGED
|
@@ -6,8 +6,8 @@ import { isString } from "@thi.ng/checks/is-string";
|
|
|
6
6
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
7
7
|
import { assert } from "@thi.ng/errors/assert";
|
|
8
8
|
import { unsupported } from "@thi.ng/errors/unsupported";
|
|
9
|
+
import { utf8Length } from "@thi.ng/strings/utf8";
|
|
9
10
|
import { bytes, str, u8, u8array } from "@thi.ng/transducers-binary/bytes";
|
|
10
|
-
import { utf8Length } from "@thi.ng/transducers-binary/utf8";
|
|
11
11
|
import { mapcat } from "@thi.ng/transducers/mapcat";
|
|
12
12
|
var Type = /* @__PURE__ */ ((Type2) => {
|
|
13
13
|
Type2[Type2["INT"] = 0] = "INT";
|
|
@@ -25,8 +25,8 @@ var Lit = /* @__PURE__ */ ((Lit2) => {
|
|
|
25
25
|
return Lit2;
|
|
26
26
|
})(Lit || {});
|
|
27
27
|
const FLOAT_RE = /^[0-9.-]+$/;
|
|
28
|
-
const encode = (x, cap = 1024) => bytes(cap,
|
|
29
|
-
const
|
|
28
|
+
const encode = (x, cap = 1024) => bytes(cap, __encodeBin(x));
|
|
29
|
+
const __encodeBin = defmulti(
|
|
30
30
|
(x) => isNumber(x) ? Math.floor(x) !== x ? 1 /* FLOAT */ : 0 /* INT */ : isBoolean(x) ? 0 /* INT */ : isString(x) ? 2 /* STR */ : x instanceof Uint8Array ? 3 /* BINARY */ : isArrayLike(x) ? 5 /* LIST */ : isPlainObject(x) ? 4 /* DICT */ : unsupported(`unsupported data type: ${x}`),
|
|
31
31
|
{},
|
|
32
32
|
{
|
|
@@ -49,13 +49,13 @@ const encodeBin = defmulti(
|
|
|
49
49
|
[2 /* STR */]: (x) => [str(utf8Length(x) + ":" + x)],
|
|
50
50
|
[5 /* LIST */]: (x) => [
|
|
51
51
|
u8(108 /* LIST */),
|
|
52
|
-
...mapcat(
|
|
52
|
+
...mapcat(__encodeBin, x),
|
|
53
53
|
u8(101 /* END */)
|
|
54
54
|
],
|
|
55
55
|
[4 /* DICT */]: (x) => [
|
|
56
56
|
u8(100 /* DICT */),
|
|
57
57
|
...mapcat(
|
|
58
|
-
(k) =>
|
|
58
|
+
(k) => __encodeBin(k).concat(__encodeBin(x[k])),
|
|
59
59
|
Object.keys(x).sort()
|
|
60
60
|
),
|
|
61
61
|
u8(101 /* END */)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/bencode",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.123",
|
|
4
4
|
"description": "Bencode binary encoder / decoder with optional UTF8 encoding & floating point support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/bencode",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,18 +36,19 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/arrays": "^2.9.
|
|
40
|
-
"@thi.ng/checks": "^3.6.
|
|
41
|
-
"@thi.ng/defmulti": "^3.0.
|
|
42
|
-
"@thi.ng/errors": "^2.5.
|
|
43
|
-
"@thi.ng/
|
|
44
|
-
"@thi.ng/transducers
|
|
39
|
+
"@thi.ng/arrays": "^2.9.7",
|
|
40
|
+
"@thi.ng/checks": "^3.6.5",
|
|
41
|
+
"@thi.ng/defmulti": "^3.0.40",
|
|
42
|
+
"@thi.ng/errors": "^2.5.8",
|
|
43
|
+
"@thi.ng/strings": "^3.7.34",
|
|
44
|
+
"@thi.ng/transducers": "^9.0.6",
|
|
45
|
+
"@thi.ng/transducers-binary": "^2.1.121"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "^7.
|
|
48
|
-
"esbuild": "^0.21.
|
|
48
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
49
|
+
"esbuild": "^0.21.5",
|
|
49
50
|
"typedoc": "^0.25.13",
|
|
50
|
-
"typescript": "^5.
|
|
51
|
+
"typescript": "^5.5.2"
|
|
51
52
|
},
|
|
52
53
|
"keywords": [
|
|
53
54
|
"array",
|
|
@@ -82,5 +83,5 @@
|
|
|
82
83
|
"thi.ng": {
|
|
83
84
|
"alias": "bc"
|
|
84
85
|
},
|
|
85
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
86
87
|
}
|