uint8arraylist 1.1.0 → 1.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/README.md +3 -0
- package/dist/src/index.d.ts +12 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +34 -5
- package/dist/src/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +46 -7
package/README.md
CHANGED
package/dist/src/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
declare type Appendable = Uint8ArrayList | Uint8Array;
|
|
1
2
|
export declare class Uint8ArrayList implements Iterable<Uint8Array> {
|
|
2
3
|
private bufs;
|
|
3
4
|
length: number;
|
|
4
|
-
constructor(...data:
|
|
5
|
+
constructor(...data: Appendable[]);
|
|
5
6
|
[Symbol.iterator](): Generator<Uint8Array, void, undefined>;
|
|
6
|
-
|
|
7
|
+
get byteLength(): number;
|
|
8
|
+
append(...bufs: Appendable[]): void;
|
|
9
|
+
appendAll(bufs: Appendable[]): void;
|
|
7
10
|
get(index: number): number;
|
|
8
11
|
/**
|
|
9
12
|
* Remove bytes from the front of the pool
|
|
10
13
|
*/
|
|
11
14
|
consume(bytes: number): void;
|
|
12
|
-
|
|
15
|
+
slice(beginInclusive?: number, endExclusive?: number): Uint8Array;
|
|
16
|
+
subarray(beginInclusive?: number, endExclusive?: number): Uint8ArrayList;
|
|
17
|
+
_subList(beginInclusive?: number, endExclusive?: number): {
|
|
18
|
+
bufs: Uint8Array[];
|
|
19
|
+
length: number;
|
|
20
|
+
};
|
|
13
21
|
}
|
|
22
|
+
export {};
|
|
14
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAe,YAAW,QAAQ,CAAC,UAAU,CAAC;IACzD,OAAO,CAAC,IAAI,CAAc;IACnB,MAAM,EAAE,MAAM,CAAA;gBAER,GAAG,IAAI,EAAE,UAAU,EAAE;IAOhC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAInB,MAAM,CAAE,GAAG,IAAI,EAAE,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,aAAK,UAAU,GAAG,cAAc,GAAG,UAAU,CAAA;AAE7C,qBAAa,cAAe,YAAW,QAAQ,CAAC,UAAU,CAAC;IACzD,OAAO,CAAC,IAAI,CAAc;IACnB,MAAM,EAAE,MAAM,CAAA;gBAER,GAAG,IAAI,EAAE,UAAU,EAAE;IAOhC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAInB,IAAI,UAAU,WAEb;IAED,MAAM,CAAE,GAAG,IAAI,EAAE,UAAU,EAAE;IAI7B,SAAS,CAAE,IAAI,EAAE,UAAU,EAAE;IAgB7B,GAAG,CAAE,KAAK,EAAE,MAAM;IAoBlB;;OAEG;IACH,OAAO,CAAE,KAAK,EAAE,MAAM;IAsBtB,KAAK,CAAE,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;IAMrD,QAAQ,CAAE,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;IASxD,QAAQ,CAAE,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;;;;CA2DzD"}
|
package/dist/src/index.js
CHANGED
|
@@ -3,16 +3,28 @@ export class Uint8ArrayList {
|
|
|
3
3
|
constructor(...data) {
|
|
4
4
|
this.bufs = [];
|
|
5
5
|
this.length = 0;
|
|
6
|
-
this.
|
|
6
|
+
this.appendAll(data);
|
|
7
7
|
}
|
|
8
8
|
*[Symbol.iterator]() {
|
|
9
9
|
yield* this.bufs;
|
|
10
10
|
}
|
|
11
|
+
get byteLength() {
|
|
12
|
+
return this.length;
|
|
13
|
+
}
|
|
11
14
|
append(...bufs) {
|
|
15
|
+
this.appendAll(bufs);
|
|
16
|
+
}
|
|
17
|
+
appendAll(bufs) {
|
|
12
18
|
let length = 0;
|
|
13
19
|
for (const buf of bufs) {
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
if (buf instanceof Uint8Array) {
|
|
21
|
+
length += buf.byteLength;
|
|
22
|
+
this.bufs.push(buf);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
length += buf.length;
|
|
26
|
+
this.bufs = this.bufs.concat(buf.bufs);
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
this.length += length;
|
|
18
30
|
}
|
|
@@ -53,11 +65,28 @@ export class Uint8ArrayList {
|
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
|
-
|
|
68
|
+
slice(beginInclusive, endExclusive) {
|
|
69
|
+
const { bufs, length } = this._subList(beginInclusive, endExclusive);
|
|
70
|
+
return concat(bufs, length);
|
|
71
|
+
}
|
|
72
|
+
subarray(beginInclusive, endExclusive) {
|
|
73
|
+
const { bufs } = this._subList(beginInclusive, endExclusive);
|
|
74
|
+
const list = new Uint8ArrayList();
|
|
75
|
+
list.appendAll(bufs);
|
|
76
|
+
return list;
|
|
77
|
+
}
|
|
78
|
+
_subList(beginInclusive, endExclusive) {
|
|
79
|
+
if (beginInclusive == null && endExclusive == null) {
|
|
80
|
+
return { bufs: this.bufs, length: this.length };
|
|
81
|
+
}
|
|
82
|
+
beginInclusive = beginInclusive ?? 0;
|
|
57
83
|
endExclusive = endExclusive ?? (this.length > 0 ? this.length : 0);
|
|
58
84
|
if (beginInclusive < 0 || endExclusive > this.length) {
|
|
59
85
|
throw new RangeError('index out of bounds');
|
|
60
86
|
}
|
|
87
|
+
if (beginInclusive === endExclusive) {
|
|
88
|
+
return { bufs: [], length: 0 };
|
|
89
|
+
}
|
|
61
90
|
const bufs = [];
|
|
62
91
|
let offset = 0;
|
|
63
92
|
for (const buf of this.bufs) {
|
|
@@ -90,7 +119,7 @@ export class Uint8ArrayList {
|
|
|
90
119
|
break;
|
|
91
120
|
}
|
|
92
121
|
}
|
|
93
|
-
return
|
|
122
|
+
return { bufs, length: endExclusive - beginInclusive };
|
|
94
123
|
}
|
|
95
124
|
}
|
|
96
125
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIpC,MAAM,OAAO,cAAc;IAIzB,YAAa,GAAG,IAAkB;QAChC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;QAEf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACtB,CAAC;IAED,CAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjB,KAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;IACnB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,MAAM,CAAE,GAAG,IAAkB;QAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACtB,CAAC;IAED,SAAS,CAAE,IAAkB;QAC3B,IAAI,MAAM,GAAG,CAAC,CAAA;QAEd,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,IAAI,GAAG,YAAY,UAAU,EAAE;gBAC7B,MAAM,IAAI,GAAG,CAAC,UAAU,CAAA;gBACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;aACpB;iBAAM;gBACL,MAAM,IAAI,GAAG,CAAC,MAAM,CAAA;gBACpB,IAAI,CA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,YAAY,GAAG,cAAc,EAAE,CAAA;IACxD,CAAC;CACF"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import { concat } from 'uint8arrays'
|
|
2
2
|
|
|
3
|
+
type Appendable = Uint8ArrayList | Uint8Array
|
|
4
|
+
|
|
3
5
|
export class Uint8ArrayList implements Iterable<Uint8Array> {
|
|
4
6
|
private bufs: Uint8Array[]
|
|
5
7
|
public length: number
|
|
6
8
|
|
|
7
|
-
constructor (...data:
|
|
9
|
+
constructor (...data: Appendable[]) {
|
|
8
10
|
this.bufs = []
|
|
9
11
|
this.length = 0
|
|
10
12
|
|
|
11
|
-
this.
|
|
13
|
+
this.appendAll(data)
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
* [Symbol.iterator] () {
|
|
15
17
|
yield * this.bufs
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
get byteLength () {
|
|
21
|
+
return this.length
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
append (...bufs: Appendable[]) {
|
|
25
|
+
this.appendAll(bufs)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
appendAll (bufs: Appendable[]) {
|
|
19
29
|
let length = 0
|
|
20
30
|
|
|
21
31
|
for (const buf of bufs) {
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
if (buf instanceof Uint8Array) {
|
|
33
|
+
length += buf.byteLength
|
|
34
|
+
this.bufs.push(buf)
|
|
35
|
+
} else {
|
|
36
|
+
length += buf.length
|
|
37
|
+
this.bufs = this.bufs.concat(buf.bufs)
|
|
38
|
+
}
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
this.length += length
|
|
@@ -71,13 +86,37 @@ export class Uint8ArrayList implements Iterable<Uint8Array> {
|
|
|
71
86
|
}
|
|
72
87
|
}
|
|
73
88
|
|
|
74
|
-
|
|
89
|
+
slice (beginInclusive?: number, endExclusive?: number) {
|
|
90
|
+
const { bufs, length } = this._subList(beginInclusive, endExclusive)
|
|
91
|
+
|
|
92
|
+
return concat(bufs, length)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
subarray (beginInclusive?: number, endExclusive?: number) {
|
|
96
|
+
const { bufs } = this._subList(beginInclusive, endExclusive)
|
|
97
|
+
|
|
98
|
+
const list = new Uint8ArrayList()
|
|
99
|
+
list.appendAll(bufs)
|
|
100
|
+
|
|
101
|
+
return list
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_subList (beginInclusive?: number, endExclusive?: number) {
|
|
105
|
+
if (beginInclusive == null && endExclusive == null) {
|
|
106
|
+
return { bufs: this.bufs, length: this.length }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
beginInclusive = beginInclusive ?? 0
|
|
75
110
|
endExclusive = endExclusive ?? (this.length > 0 ? this.length : 0)
|
|
76
111
|
|
|
77
112
|
if (beginInclusive < 0 || endExclusive > this.length) {
|
|
78
113
|
throw new RangeError('index out of bounds')
|
|
79
114
|
}
|
|
80
115
|
|
|
116
|
+
if (beginInclusive === endExclusive) {
|
|
117
|
+
return { bufs: [], length: 0 }
|
|
118
|
+
}
|
|
119
|
+
|
|
81
120
|
const bufs: Uint8Array[] = []
|
|
82
121
|
let offset = 0
|
|
83
122
|
|
|
@@ -119,6 +158,6 @@ export class Uint8ArrayList implements Iterable<Uint8Array> {
|
|
|
119
158
|
}
|
|
120
159
|
}
|
|
121
160
|
|
|
122
|
-
return
|
|
161
|
+
return { bufs, length: endExclusive - beginInclusive }
|
|
123
162
|
}
|
|
124
163
|
}
|