@gmod/trix 2.0.9 → 3.0.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/dist/index.d.ts +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/util.d.ts +2 -0
- package/dist/util.js +21 -0
- package/dist/util.js.map +1 -0
- package/esm/index.d.ts +1 -1
- package/esm/index.js +8 -7
- package/esm/index.js.map +1 -1
- package/esm/util.d.ts +2 -0
- package/esm/util.js +17 -0
- package/esm/util.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +9 -14
- package/src/util.ts +16 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const util_1 = require("./util");
|
|
13
13
|
const CHUNK_SIZE = 65536;
|
|
14
14
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
15
15
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
@@ -40,10 +40,11 @@ class Trix {
|
|
|
40
40
|
}
|
|
41
41
|
let { end, buffer } = res;
|
|
42
42
|
let done = false;
|
|
43
|
+
const decoder = new TextDecoder('utf8');
|
|
44
|
+
const str = decoder.decode(buffer);
|
|
43
45
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
44
46
|
while (!done) {
|
|
45
47
|
let foundSomething = false;
|
|
46
|
-
const str = buffer.toString();
|
|
47
48
|
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
48
49
|
// since the buffer fetch could get halfway into a record
|
|
49
50
|
const lines = str
|
|
@@ -73,13 +74,13 @@ class Trix {
|
|
|
73
74
|
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
74
75
|
// then refetch
|
|
75
76
|
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
76
|
-
const res2 = yield this.ixFile.read(
|
|
77
|
+
const res2 = yield this.ixFile.read(CHUNK_SIZE, end, opts);
|
|
77
78
|
// early break if empty response
|
|
78
|
-
if (
|
|
79
|
+
if (res2.length === 0) {
|
|
79
80
|
resultArr = resultArr.concat(hits);
|
|
80
81
|
break;
|
|
81
82
|
}
|
|
82
|
-
buffer =
|
|
83
|
+
buffer = (0, util_1.concatUint8Array)([buffer, res2]);
|
|
83
84
|
end += CHUNK_SIZE;
|
|
84
85
|
}
|
|
85
86
|
// if we have filled up the hits, or we are detected to be done via the
|
|
@@ -125,8 +126,11 @@ class Trix {
|
|
|
125
126
|
if (len < 0) {
|
|
126
127
|
return undefined;
|
|
127
128
|
}
|
|
128
|
-
const
|
|
129
|
-
return
|
|
129
|
+
const buffer = yield this.ixFile.read(len, start, opts);
|
|
130
|
+
return {
|
|
131
|
+
buffer,
|
|
132
|
+
end,
|
|
133
|
+
};
|
|
130
134
|
});
|
|
131
135
|
}
|
|
132
136
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,iCAAyC;AAEzC,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,4EAA4E;AAC5E,iEAAiE;AACjE,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,8CAA8C;AAC9C,SAAS,MAAM,CAAI,CAAM,EAAE,GAAuB;IAChD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IACtB,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACrB,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAA;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC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,CAAC,CAAA;gBACvC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAU,CAAA;YAC/B,CAAC,CAAC,CAAA;QACN,CAAC;KAAA;IAEa,UAAU,CACtB,UAAkB,EAClB,IAA+B;;YAE/B,IAAI,KAAK,GAAG,CAAC,CAAA;YACb,IAAI,GAAG,GAAG,KAAK,CAAA;YACf,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;YACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;gBACnC,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;gBAClD,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;oBAC5B,KAAK,GAAG,KAAK,CAAA;oBACb,GAAG,GAAG,KAAK,GAAG,KAAK,CAAA;gBACrB,CAAC;YACH,CAAC;YAED,sDAAsD;YACtD,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,CAAA;YACvB,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;gBACZ,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;YACvD,OAAO;gBACL,MAAM;gBACN,GAAG;aACJ,CAAA;QACH,CAAC;KAAA;CACF;AA5HD,uBA4HC"}
|
package/dist/util.d.ts
ADDED
package/dist/util.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sum = sum;
|
|
4
|
+
exports.concatUint8Array = concatUint8Array;
|
|
5
|
+
function sum(array) {
|
|
6
|
+
let sum = 0;
|
|
7
|
+
for (const entry of array) {
|
|
8
|
+
sum += entry.length;
|
|
9
|
+
}
|
|
10
|
+
return sum;
|
|
11
|
+
}
|
|
12
|
+
function concatUint8Array(args) {
|
|
13
|
+
const mergedArray = new Uint8Array(sum(args));
|
|
14
|
+
let offset = 0;
|
|
15
|
+
for (const entry of args) {
|
|
16
|
+
mergedArray.set(entry, offset);
|
|
17
|
+
offset += entry.length;
|
|
18
|
+
}
|
|
19
|
+
return mergedArray;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAAA,kBAMC;AACD,4CAQC;AAfD,SAAgB,GAAG,CAAC,KAAmB;IACrC,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,GAAG,IAAI,KAAK,CAAC,MAAM,CAAA;IACrB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AACD,SAAgB,gBAAgB,CAAC,IAAkB;IACjD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;IACxB,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { concatUint8Array } from './util';
|
|
2
2
|
const CHUNK_SIZE = 65536;
|
|
3
3
|
// this is the number of hex characters to use for the address in ixixx, see
|
|
4
4
|
// https://github.com/GMOD/ixixx-js/blob/master/src/index.ts#L182
|
|
@@ -31,10 +31,11 @@ export default class Trix {
|
|
|
31
31
|
}
|
|
32
32
|
let { end, buffer } = res;
|
|
33
33
|
let done = false;
|
|
34
|
+
const decoder = new TextDecoder('utf8');
|
|
35
|
+
const str = decoder.decode(buffer);
|
|
34
36
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
35
37
|
while (!done) {
|
|
36
38
|
let foundSomething = false;
|
|
37
|
-
const str = buffer.toString();
|
|
38
39
|
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
39
40
|
// since the buffer fetch could get halfway into a record
|
|
40
41
|
const lines = str
|
|
@@ -64,13 +65,13 @@ export default class Trix {
|
|
|
64
65
|
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
65
66
|
// then refetch
|
|
66
67
|
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
67
|
-
const res2 = await this.ixFile.read(
|
|
68
|
+
const res2 = await this.ixFile.read(CHUNK_SIZE, end, opts);
|
|
68
69
|
// early break if empty response
|
|
69
|
-
if (
|
|
70
|
+
if (res2.length === 0) {
|
|
70
71
|
resultArr = resultArr.concat(hits);
|
|
71
72
|
break;
|
|
72
73
|
}
|
|
73
|
-
buffer =
|
|
74
|
+
buffer = concatUint8Array([buffer, res2]);
|
|
74
75
|
end += CHUNK_SIZE;
|
|
75
76
|
}
|
|
76
77
|
// if we have filled up the hits, or we are detected to be done via the
|
|
@@ -115,9 +116,9 @@ export default class Trix {
|
|
|
115
116
|
if (len < 0) {
|
|
116
117
|
return undefined;
|
|
117
118
|
}
|
|
118
|
-
const
|
|
119
|
+
const buffer = await this.ixFile.read(len, start, opts);
|
|
119
120
|
return {
|
|
120
|
-
|
|
121
|
+
buffer,
|
|
121
122
|
end,
|
|
122
123
|
};
|
|
123
124
|
}
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names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AC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACvD,OAAO;YACL,MAAM;YACN,GAAG;SACJ,CAAA;IACH,CAAC;CACF"}
|
package/esm/util.d.ts
ADDED
package/esm/util.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function sum(array) {
|
|
2
|
+
let sum = 0;
|
|
3
|
+
for (const entry of array) {
|
|
4
|
+
sum += entry.length;
|
|
5
|
+
}
|
|
6
|
+
return sum;
|
|
7
|
+
}
|
|
8
|
+
export function concatUint8Array(args) {
|
|
9
|
+
const mergedArray = new Uint8Array(sum(args));
|
|
10
|
+
let offset = 0;
|
|
11
|
+
for (const entry of args) {
|
|
12
|
+
mergedArray.set(entry, offset);
|
|
13
|
+
offset += entry.length;
|
|
14
|
+
}
|
|
15
|
+
return mergedArray;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=util.js.map
|
package/esm/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,CAAC,KAAmB;IACrC,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,GAAG,IAAI,KAAK,CAAC,MAAM,CAAA;IACrB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,IAAkB;IACjD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAA;IACxB,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
2
|
+
"version": "3.0.0",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"@typescript-eslint/parser": "^8.4.0",
|
|
31
31
|
"eslint": "^9.0.0",
|
|
32
32
|
"eslint-plugin-unicorn": "^55.0.0",
|
|
33
|
-
"generic-
|
|
33
|
+
"generic-filehandle2": "^0.0.1",
|
|
34
34
|
"prettier": "^3.3.3",
|
|
35
35
|
"rimraf": "^6.0.1",
|
|
36
|
-
"typescript": "^5.
|
|
36
|
+
"typescript": "^5.7.0",
|
|
37
37
|
"typescript-eslint": "^8.4.0",
|
|
38
38
|
"vitest": "^2.0.5"
|
|
39
39
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { GenericFilehandle } from 'generic-filehandle2'
|
|
2
|
+
import { concatUint8Array } from './util'
|
|
3
3
|
|
|
4
4
|
const CHUNK_SIZE = 65536
|
|
5
5
|
|
|
@@ -36,10 +36,11 @@ export default class Trix {
|
|
|
36
36
|
|
|
37
37
|
let { end, buffer } = res
|
|
38
38
|
let done = false
|
|
39
|
+
const decoder = new TextDecoder('utf8')
|
|
40
|
+
const str = decoder.decode(buffer)
|
|
39
41
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
40
42
|
while (!done) {
|
|
41
43
|
let foundSomething = false
|
|
42
|
-
const str = buffer.toString()
|
|
43
44
|
|
|
44
45
|
// slice to lastIndexOf('\n') to make sure we get complete records
|
|
45
46
|
// since the buffer fetch could get halfway into a record
|
|
@@ -73,20 +74,14 @@ export default class Trix {
|
|
|
73
74
|
// if we are not done, and we haven't filled up maxResults with hits yet,
|
|
74
75
|
// then refetch
|
|
75
76
|
if (resultArr.length + hits.length < this.maxResults && !done) {
|
|
76
|
-
const res2 = await this.ixFile.read(
|
|
77
|
-
Buffer.alloc(CHUNK_SIZE),
|
|
78
|
-
0,
|
|
79
|
-
CHUNK_SIZE,
|
|
80
|
-
end,
|
|
81
|
-
opts,
|
|
82
|
-
)
|
|
77
|
+
const res2 = await this.ixFile.read(CHUNK_SIZE, end, opts)
|
|
83
78
|
|
|
84
79
|
// early break if empty response
|
|
85
|
-
if (
|
|
80
|
+
if (res2.length === 0) {
|
|
86
81
|
resultArr = resultArr.concat(hits)
|
|
87
82
|
break
|
|
88
83
|
}
|
|
89
|
-
buffer =
|
|
84
|
+
buffer = concatUint8Array([buffer, res2])
|
|
90
85
|
end += CHUNK_SIZE
|
|
91
86
|
}
|
|
92
87
|
|
|
@@ -139,9 +134,9 @@ export default class Trix {
|
|
|
139
134
|
if (len < 0) {
|
|
140
135
|
return undefined
|
|
141
136
|
}
|
|
142
|
-
const
|
|
137
|
+
const buffer = await this.ixFile.read(len, start, opts)
|
|
143
138
|
return {
|
|
144
|
-
|
|
139
|
+
buffer,
|
|
145
140
|
end,
|
|
146
141
|
}
|
|
147
142
|
}
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function sum(array: Uint8Array[]) {
|
|
2
|
+
let sum = 0
|
|
3
|
+
for (const entry of array) {
|
|
4
|
+
sum += entry.length
|
|
5
|
+
}
|
|
6
|
+
return sum
|
|
7
|
+
}
|
|
8
|
+
export function concatUint8Array(args: Uint8Array[]) {
|
|
9
|
+
const mergedArray = new Uint8Array(sum(args))
|
|
10
|
+
let offset = 0
|
|
11
|
+
for (const entry of args) {
|
|
12
|
+
mergedArray.set(entry, offset)
|
|
13
|
+
offset += entry.length
|
|
14
|
+
}
|
|
15
|
+
return mergedArray
|
|
16
|
+
}
|