@thi.ng/bitstream 2.2.67 → 2.3.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/CHANGELOG.md +9 -1
- package/README.md +7 -3
- package/input.d.ts +6 -6
- package/input.js +16 -16
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-08-
|
|
3
|
+
- **Last updated**: 2024-08-19T13:45:57Z
|
|
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,14 @@ 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.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/bitstream@2.3.0) (2024-08-19)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add support for unsafe reads in BitInputStream ([5edd4dd](https://github.com/thi-ng/umbrella/commit/5edd4dd))
|
|
17
|
+
- add optional arg to disable bounds checking in all read methods
|
|
18
|
+
- update readme
|
|
19
|
+
|
|
12
20
|
### [2.2.61](https://github.com/thi-ng/umbrella/tree/@thi.ng/bitstream@2.2.61) (2024-06-21)
|
|
13
21
|
|
|
14
22
|
#### ♻️ Refactoring
|
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 199 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
|
>
|
|
@@ -67,7 +67,7 @@ For Node.js REPL:
|
|
|
67
67
|
const bit = await import("@thi.ng/bitstream");
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 1.
|
|
70
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.35 KB
|
|
71
71
|
|
|
72
72
|
## Dependencies
|
|
73
73
|
|
|
@@ -131,7 +131,11 @@ auto-configured input stream can also be obtained via `output.reader()`.
|
|
|
131
131
|
The class too implements the ES6 Iterator API for **bitwise** read
|
|
132
132
|
access, as well as a `read()` method to read bitfields.
|
|
133
133
|
|
|
134
|
-
**Note**:
|
|
134
|
+
**Note**: By default, attempting to read beyond capacity will throw an EOF
|
|
135
|
+
error. However, all available read methods in `BitInputStream` support an
|
|
136
|
+
optional argument to disable bounds checking (by passing `false` as extra arg).
|
|
137
|
+
These unsafe reads will result in undefined behavior once read past EOF — use
|
|
138
|
+
with caution!
|
|
135
139
|
|
|
136
140
|
Using `input.seek(pos)`, the read position can be repositioned within
|
|
137
141
|
stream limits.
|
package/input.d.ts
CHANGED
|
@@ -10,12 +10,12 @@ export declare class BitInputStream {
|
|
|
10
10
|
get length(): number;
|
|
11
11
|
get position(): number;
|
|
12
12
|
seek(pos: number): BitInputStream;
|
|
13
|
-
read(wordSize?: number): number;
|
|
14
|
-
readFields(fields: number[]): number[];
|
|
15
|
-
readWords(n: number, wordSize?: number): number[];
|
|
16
|
-
readStruct(fields: [string, number][]): any;
|
|
17
|
-
readBit(): number;
|
|
18
|
-
protected _read(wordSize: number): number;
|
|
13
|
+
read(wordSize?: number, safe?: boolean): number;
|
|
14
|
+
readFields(fields: number[], safe?: boolean): number[];
|
|
15
|
+
readWords(n: number, wordSize?: number, safe?: boolean): number[];
|
|
16
|
+
readStruct(fields: [string, number][], safe?: boolean): any;
|
|
17
|
+
readBit(safe?: boolean): number;
|
|
18
|
+
protected _read(wordSize: number, safe?: boolean): number;
|
|
19
19
|
protected checkLimit(requested: number): void;
|
|
20
20
|
}
|
|
21
21
|
//# sourceMappingURL=input.d.ts.map
|
package/input.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
2
2
|
import { illegalState } from "@thi.ng/errors/illegal-state";
|
|
3
|
-
const U32 =
|
|
3
|
+
const U32 = 4294967296;
|
|
4
4
|
class BitInputStream {
|
|
5
5
|
buffer;
|
|
6
6
|
start;
|
|
@@ -42,42 +42,42 @@ class BitInputStream {
|
|
|
42
42
|
this.bitPos = pos;
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
|
-
read(wordSize = 1) {
|
|
45
|
+
read(wordSize = 1, safe = true) {
|
|
46
46
|
if (wordSize > 32) {
|
|
47
|
-
return this.read(wordSize - 32) * U32 + this.read(32);
|
|
47
|
+
return this.read(wordSize - 32, safe) * U32 + this.read(32, safe);
|
|
48
48
|
} else if (wordSize > 8) {
|
|
49
49
|
let out = 0;
|
|
50
50
|
let n = wordSize & -8;
|
|
51
51
|
let msb = wordSize - n;
|
|
52
52
|
if (msb > 0) {
|
|
53
|
-
out = this._read(msb);
|
|
53
|
+
out = this._read(msb, safe);
|
|
54
54
|
}
|
|
55
55
|
while (n > 0) {
|
|
56
|
-
out = (out << 8 | this._read(8)) >>> 0;
|
|
56
|
+
out = (out << 8 | this._read(8, safe)) >>> 0;
|
|
57
57
|
n -= 8;
|
|
58
58
|
}
|
|
59
59
|
return out;
|
|
60
60
|
} else {
|
|
61
|
-
return this._read(wordSize);
|
|
61
|
+
return this._read(wordSize, safe);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
readFields(fields) {
|
|
65
|
-
return fields.map((word) => this.read(word));
|
|
64
|
+
readFields(fields, safe = true) {
|
|
65
|
+
return fields.map((word) => this.read(word, safe));
|
|
66
66
|
}
|
|
67
|
-
readWords(n, wordSize = 8) {
|
|
67
|
+
readWords(n, wordSize = 8, safe = true) {
|
|
68
68
|
let out = [];
|
|
69
69
|
while (n-- > 0) {
|
|
70
|
-
out.push(this.read(wordSize));
|
|
70
|
+
out.push(this.read(wordSize, safe));
|
|
71
71
|
}
|
|
72
72
|
return out;
|
|
73
73
|
}
|
|
74
|
-
readStruct(fields) {
|
|
74
|
+
readStruct(fields, safe = true) {
|
|
75
75
|
return fields.reduce((acc, [id, word]) => {
|
|
76
|
-
return acc[id] = this.read(word), acc;
|
|
76
|
+
return acc[id] = this.read(word, safe), acc;
|
|
77
77
|
}, {});
|
|
78
78
|
}
|
|
79
|
-
readBit() {
|
|
80
|
-
this.checkLimit(1);
|
|
79
|
+
readBit(safe = true) {
|
|
80
|
+
safe && this.checkLimit(1);
|
|
81
81
|
this.bit--;
|
|
82
82
|
this.bitPos++;
|
|
83
83
|
let out = this.buffer[this.pos] >>> this.bit & 1;
|
|
@@ -87,8 +87,8 @@ class BitInputStream {
|
|
|
87
87
|
}
|
|
88
88
|
return out;
|
|
89
89
|
}
|
|
90
|
-
_read(wordSize) {
|
|
91
|
-
this.checkLimit(wordSize);
|
|
90
|
+
_read(wordSize, safe = true) {
|
|
91
|
+
safe && this.checkLimit(wordSize);
|
|
92
92
|
let l = this.bit - wordSize, out;
|
|
93
93
|
if (l >= 0) {
|
|
94
94
|
this.bit = l;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/bitstream",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "ES6 iterator based read/write bit streams with support for variable word widths",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/errors": "^2.5.
|
|
39
|
+
"@thi.ng/errors": "^2.5.15"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@microsoft/api-extractor": "^7.47.5",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"rle-pack"
|
|
82
82
|
]
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "bfbc227cf5ca2d3c2984b3d4713eebd6225cbd54\n"
|
|
85
85
|
}
|