@ssttevee/streamsearch 0.3.0 → 0.4.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 +57 -2
- package/lib/index.cjs +29 -265
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +13 -9
- package/lib/index.mjs +21 -256
- package/lib/index.mjs.map +1 -1
- package/lib/iterate-chunks-concatted.cjs +15 -0
- package/lib/iterate-chunks-concatted.cjs.map +1 -0
- package/lib/iterate-chunks-concatted.d.ts +2 -0
- package/lib/iterate-chunks-concatted.mjs +13 -0
- package/lib/iterate-chunks-concatted.mjs.map +1 -0
- package/lib/iterate-chunks.cjs +22 -0
- package/lib/iterate-chunks.cjs.map +1 -0
- package/lib/iterate-chunks.d.ts +2 -0
- package/lib/iterate-chunks.mjs +20 -0
- package/lib/iterate-chunks.mjs.map +1 -0
- package/lib/iterate-strings.cjs +16 -0
- package/lib/iterate-strings.cjs.map +1 -0
- package/lib/iterate-strings.d.ts +2 -0
- package/lib/iterate-strings.mjs +14 -0
- package/lib/iterate-strings.mjs.map +1 -0
- package/lib/iterator.cjs +42 -0
- package/lib/iterator.cjs.map +1 -0
- package/lib/iterator.d.ts +7 -0
- package/lib/iterator.mjs +40 -0
- package/lib/iterator.mjs.map +1 -0
- package/lib/queueable.cjs +55 -0
- package/lib/queueable.cjs.map +1 -0
- package/lib/queueable.d.ts +11 -11
- package/lib/queueable.mjs +53 -0
- package/lib/queueable.mjs.map +1 -0
- package/lib/readable.cjs +36 -0
- package/lib/readable.cjs.map +1 -0
- package/lib/readable.d.ts +7 -7
- package/lib/readable.mjs +34 -0
- package/lib/readable.mjs.map +1 -0
- package/lib/search-BXQkEs3p.js +97 -0
- package/lib/search-BXQkEs3p.js.map +1 -0
- package/lib/search-D_ihawrM.js +108 -0
- package/lib/search-D_ihawrM.js.map +1 -0
- package/lib/{index.js → search.cjs} +179 -263
- package/lib/search.cjs.map +1 -0
- package/lib/search.d.ts +13 -14
- package/lib/search.mjs +185 -0
- package/lib/search.mjs.map +1 -0
- package/lib/split.cjs +26 -0
- package/lib/split.cjs.map +1 -0
- package/lib/split.d.ts +1 -0
- package/lib/split.mjs +24 -0
- package/lib/split.mjs.map +1 -0
- package/package.json +85 -37
- package/lib/index.js.map +0 -1
package/lib/index.mjs
CHANGED
|
@@ -1,260 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { iterateStrings } from './iterate-strings.mjs';
|
|
2
|
+
export { iterateChunks } from './iterate-chunks.mjs';
|
|
3
|
+
export { iterateChunksConcatted } from './iterate-chunks-concatted.mjs';
|
|
4
|
+
export { IteratorStreamSearch } from './iterator.mjs';
|
|
5
|
+
export { QueueableStreamSearch } from './queueable.mjs';
|
|
6
|
+
export { ReadableStreamSearch } from './readable.mjs';
|
|
7
|
+
export { MATCH, StreamSearch } from './search.mjs';
|
|
8
|
+
export { split } from './split.mjs';
|
|
9
|
+
import 'uint8arrays/concat';
|
|
10
|
+
import 'uint8arrays/to-string';
|
|
11
|
+
import 'uint8arrays/from-string';
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
function jsmemcmp(buf1, pos1, buf2, pos2, len) {
|
|
14
|
-
const fn1 = coerce(buf1);
|
|
15
|
-
const fn2 = coerce(buf2);
|
|
16
|
-
for (var i = 0; i < len; ++i) {
|
|
17
|
-
if (fn1(pos1 + i) !== fn2(pos2 + i)) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
function createOccurenceTable(s) {
|
|
24
|
-
// Populate occurrence table with analysis of the needle,
|
|
25
|
-
// ignoring last letter.
|
|
26
|
-
const table = new Array(256).fill(s.length);
|
|
27
|
-
if (s.length > 1) {
|
|
28
|
-
for (let i = 0; i < s.length - 1; i++) {
|
|
29
|
-
table[s[i]] = s.length - 1 - i;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return table;
|
|
33
|
-
}
|
|
34
|
-
const MATCH = Symbol('Match');
|
|
35
|
-
class StreamSearch {
|
|
36
|
-
constructor(needle) {
|
|
37
|
-
this._lookbehind = new Uint8Array();
|
|
38
|
-
if (typeof needle === 'string') {
|
|
39
|
-
this._needle = needle = stringToArray(needle);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
this._needle = needle;
|
|
43
|
-
}
|
|
44
|
-
this._lastChar = needle[needle.length - 1];
|
|
45
|
-
this._occ = createOccurenceTable(needle);
|
|
46
|
-
}
|
|
47
|
-
feed(chunk) {
|
|
48
|
-
let pos = 0;
|
|
49
|
-
let tokens;
|
|
50
|
-
const allTokens = [];
|
|
51
|
-
while (pos !== chunk.length) {
|
|
52
|
-
[pos, ...tokens] = this._feed(chunk, pos);
|
|
53
|
-
allTokens.push(...tokens);
|
|
54
|
-
}
|
|
55
|
-
return allTokens;
|
|
56
|
-
}
|
|
57
|
-
end() {
|
|
58
|
-
const tail = this._lookbehind;
|
|
59
|
-
this._lookbehind = new Uint8Array();
|
|
60
|
-
return tail;
|
|
61
|
-
}
|
|
62
|
-
_feed(data, buf_pos) {
|
|
63
|
-
const tokens = [];
|
|
64
|
-
// Positive: points to a position in `data`
|
|
65
|
-
// pos == 3 points to data[3]
|
|
66
|
-
// Negative: points to a position in the lookbehind buffer
|
|
67
|
-
// pos == -2 points to lookbehind[lookbehind_size - 2]
|
|
68
|
-
let pos = -this._lookbehind.length;
|
|
69
|
-
if (pos < 0) {
|
|
70
|
-
// Lookbehind buffer is not empty. Perform Boyer-Moore-Horspool
|
|
71
|
-
// search with character lookup code that considers both the
|
|
72
|
-
// lookbehind buffer and the current round's haystack data.
|
|
73
|
-
//
|
|
74
|
-
// Loop until (condition 1)
|
|
75
|
-
// there is a match.
|
|
76
|
-
// or until
|
|
77
|
-
// we've moved past the position that requires the
|
|
78
|
-
// lookbehind buffer. In this case we switch to the
|
|
79
|
-
// optimized loop.
|
|
80
|
-
// or until (condition 3)
|
|
81
|
-
// the character to look at lies outside the haystack.
|
|
82
|
-
while (pos < 0 && pos <= data.length - this._needle.length) {
|
|
83
|
-
const ch = this._charAt(data, pos + this._needle.length - 1);
|
|
84
|
-
if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
|
|
85
|
-
if (pos > -this._lookbehind.length) {
|
|
86
|
-
tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
|
|
87
|
-
}
|
|
88
|
-
tokens.push(MATCH);
|
|
89
|
-
this._lookbehind = new Uint8Array();
|
|
90
|
-
return [pos + this._needle.length, ...tokens];
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
pos += this._occ[ch];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// No match.
|
|
97
|
-
if (pos < 0) {
|
|
98
|
-
// There's too little data for Boyer-Moore-Horspool to run,
|
|
99
|
-
// so we'll use a different algorithm to skip as much as
|
|
100
|
-
// we can.
|
|
101
|
-
// Forward pos until
|
|
102
|
-
// the trailing part of lookbehind + data
|
|
103
|
-
// looks like the beginning of the needle
|
|
104
|
-
// or until
|
|
105
|
-
// pos == 0
|
|
106
|
-
while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
|
|
107
|
-
pos++;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (pos >= 0) {
|
|
111
|
-
// Discard lookbehind buffer.
|
|
112
|
-
tokens.push(this._lookbehind);
|
|
113
|
-
this._lookbehind = new Uint8Array();
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
// Cut off part of the lookbehind buffer that has
|
|
117
|
-
// been processed and append the entire haystack
|
|
118
|
-
// into it.
|
|
119
|
-
const bytesToCutOff = this._lookbehind.length + pos;
|
|
120
|
-
if (bytesToCutOff > 0) {
|
|
121
|
-
// The cut off data is guaranteed not to contain the needle.
|
|
122
|
-
tokens.push(this._lookbehind.slice(0, bytesToCutOff));
|
|
123
|
-
this._lookbehind = this._lookbehind.slice(bytesToCutOff);
|
|
124
|
-
}
|
|
125
|
-
this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i) => this._charAt(data, i - this._lookbehind.length));
|
|
126
|
-
return [data.length, ...tokens];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
pos += buf_pos;
|
|
130
|
-
// Lookbehind buffer is now empty. Perform Boyer-Moore-Horspool
|
|
131
|
-
// search with optimized character lookup code that only considers
|
|
132
|
-
// the current round's haystack data.
|
|
133
|
-
while (pos <= data.length - this._needle.length) {
|
|
134
|
-
const ch = data[pos + this._needle.length - 1];
|
|
135
|
-
if (ch === this._lastChar
|
|
136
|
-
&& data[pos] === this._needle[0]
|
|
137
|
-
&& jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
|
|
138
|
-
if (pos > buf_pos) {
|
|
139
|
-
tokens.push(data.slice(buf_pos, pos));
|
|
140
|
-
}
|
|
141
|
-
tokens.push(MATCH);
|
|
142
|
-
return [pos + this._needle.length, ...tokens];
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
pos += this._occ[ch];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
// There was no match. If there's trailing haystack data that we cannot
|
|
149
|
-
// match yet using the Boyer-Moore-Horspool algorithm (because the trailing
|
|
150
|
-
// data is less than the needle size) then match using a modified
|
|
151
|
-
// algorithm that starts matching from the beginning instead of the end.
|
|
152
|
-
// Whatever trailing data is left after running this algorithm is added to
|
|
153
|
-
// the lookbehind buffer.
|
|
154
|
-
if (pos < data.length) {
|
|
155
|
-
while (pos < data.length && (data[pos] !== this._needle[0]
|
|
156
|
-
|| !jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
|
|
157
|
-
++pos;
|
|
158
|
-
}
|
|
159
|
-
if (pos < data.length) {
|
|
160
|
-
this._lookbehind = data.slice(pos);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// Everything until pos is guaranteed not to contain needle data.
|
|
164
|
-
if (pos > 0) {
|
|
165
|
-
tokens.push(data.slice(buf_pos, pos < data.length ? pos : data.length));
|
|
166
|
-
}
|
|
167
|
-
return [data.length, ...tokens];
|
|
168
|
-
}
|
|
169
|
-
_charAt(data, pos) {
|
|
170
|
-
if (pos < 0) {
|
|
171
|
-
return this._lookbehind[this._lookbehind.length + pos];
|
|
172
|
-
}
|
|
173
|
-
return data[pos];
|
|
174
|
-
}
|
|
175
|
-
;
|
|
176
|
-
_memcmp(data, pos, len) {
|
|
177
|
-
return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
|
|
178
|
-
}
|
|
179
|
-
;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use the [Async Iterator Helpers](https://github.com/tc39/proposal-async-iterator-helpers). (e.g. `AsyncIterator.from(iterateStrings(...))`)
|
|
15
|
+
*/
|
|
16
|
+
async function allStrings(iter) {
|
|
17
|
+
const segments = [];
|
|
18
|
+
for await (const value of iterateStrings(iter)) {
|
|
19
|
+
segments.push(value);
|
|
20
|
+
}
|
|
21
|
+
return segments;
|
|
180
22
|
}
|
|
181
23
|
|
|
182
|
-
|
|
183
|
-
constructor(needle, _readableStream) {
|
|
184
|
-
this._readableStream = _readableStream;
|
|
185
|
-
this._search = new StreamSearch(needle);
|
|
186
|
-
}
|
|
187
|
-
async *[Symbol.asyncIterator]() {
|
|
188
|
-
const reader = this._readableStream.getReader();
|
|
189
|
-
try {
|
|
190
|
-
while (true) {
|
|
191
|
-
const result = await reader.read();
|
|
192
|
-
if (result.done) {
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
yield* this._search.feed(result.value);
|
|
196
|
-
}
|
|
197
|
-
const tail = this._search.end();
|
|
198
|
-
if (tail.length) {
|
|
199
|
-
yield tail;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
finally {
|
|
203
|
-
reader.releaseLock();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function splitChunks(chunks, needle) {
|
|
209
|
-
const search = new StreamSearch(needle);
|
|
210
|
-
const outchunks = [[]];
|
|
211
|
-
for (const chunk of chunks) {
|
|
212
|
-
for (const token of search.feed(chunk)) {
|
|
213
|
-
if (token === MATCH) {
|
|
214
|
-
outchunks.push([]);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
outchunks[outchunks.length - 1].push(token);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const end = search.end();
|
|
222
|
-
outchunks[outchunks.length - 1].push(end);
|
|
223
|
-
return outchunks.map((chunks) => mergeArrays(...chunks));
|
|
224
|
-
}
|
|
225
|
-
function split(buf, needle) {
|
|
226
|
-
return splitChunks([buf], needle);
|
|
227
|
-
}
|
|
228
|
-
async function* chunksIterator(iter) {
|
|
229
|
-
let chunks = [];
|
|
230
|
-
for await (const value of iter) {
|
|
231
|
-
if (value === MATCH) {
|
|
232
|
-
yield chunks;
|
|
233
|
-
chunks = [];
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
chunks.push(value);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
yield chunks;
|
|
240
|
-
}
|
|
241
|
-
async function* stringIterator(iter) {
|
|
242
|
-
for await (const chunk of chunksIterator(iter)) {
|
|
243
|
-
yield chunk.map(arrayToString).join('');
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async function allStrings(iter) {
|
|
247
|
-
const segments = [];
|
|
248
|
-
for await (const value of stringIterator(iter)) {
|
|
249
|
-
segments.push(value);
|
|
250
|
-
}
|
|
251
|
-
return segments;
|
|
252
|
-
}
|
|
253
|
-
async function* arrayIterator(iter) {
|
|
254
|
-
for await (const chunk of chunksIterator(iter)) {
|
|
255
|
-
yield mergeArrays(...chunk);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export { MATCH, ReadableStreamSearch, StreamSearch, allStrings, arrayIterator, chunksIterator, split, splitChunks, stringIterator };
|
|
24
|
+
export { allStrings, iterateStrings };
|
|
260
25
|
//# sourceMappingURL=index.mjs.map
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;AAGA;;AAEG;AACI,eAAe,UAAU,CAC/B,IAA0B,EAAA;IAE1B,MAAM,QAAQ,GAAa,EAAE;IAC7B,WAAW,MAAM,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE;AAC/C,QAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;IACrB;AAEA,IAAA,OAAO,QAAQ;AAChB;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var concat = require('uint8arrays/concat');
|
|
4
|
+
var iterateChunks = require('./iterate-chunks.cjs');
|
|
5
|
+
require('./search.cjs');
|
|
6
|
+
require('uint8arrays/from-string');
|
|
7
|
+
|
|
8
|
+
async function* iterateChunksConcatted(iter) {
|
|
9
|
+
for await (const chunk of iterateChunks.iterateChunks(iter)) {
|
|
10
|
+
yield concat.concat(chunk);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.iterateChunksConcatted = iterateChunksConcatted;
|
|
15
|
+
//# sourceMappingURL=iterate-chunks-concatted.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterate-chunks-concatted.cjs","sources":["../src/iterate-chunks-concatted.ts"],"sourcesContent":[null],"names":["iterateChunks","concat"],"mappings":";;;;;;;AAKO,gBAAgB,sBAAsB,CAC5C,IAA0B,EAAA;IAE1B,WAAW,MAAM,KAAK,IAAIA,2BAAa,CAAC,IAAI,CAAC,EAAE;AAC9C,QAAA,MAAMC,aAAM,CAAC,KAAK,CAAC;IACpB;AACD;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { concat } from 'uint8arrays/concat';
|
|
2
|
+
import { iterateChunks } from './iterate-chunks.mjs';
|
|
3
|
+
import './search.mjs';
|
|
4
|
+
import 'uint8arrays/from-string';
|
|
5
|
+
|
|
6
|
+
async function* iterateChunksConcatted(iter) {
|
|
7
|
+
for await (const chunk of iterateChunks(iter)) {
|
|
8
|
+
yield concat(chunk);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { iterateChunksConcatted };
|
|
13
|
+
//# sourceMappingURL=iterate-chunks-concatted.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterate-chunks-concatted.mjs","sources":["../src/iterate-chunks-concatted.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAKO,gBAAgB,sBAAsB,CAC5C,IAA0B,EAAA;IAE1B,WAAW,MAAM,KAAK,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE;AAC9C,QAAA,MAAM,MAAM,CAAC,KAAK,CAAC;IACpB;AACD;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var search = require('./search.cjs');
|
|
4
|
+
require('uint8arrays/concat');
|
|
5
|
+
require('uint8arrays/from-string');
|
|
6
|
+
|
|
7
|
+
async function* iterateChunks(iter) {
|
|
8
|
+
let chunks = [];
|
|
9
|
+
for await (const value of iter) {
|
|
10
|
+
if (value === search.MATCH) {
|
|
11
|
+
yield chunks;
|
|
12
|
+
chunks = [];
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
chunks.push(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
yield chunks;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.iterateChunks = iterateChunks;
|
|
22
|
+
//# sourceMappingURL=iterate-chunks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterate-chunks.cjs","sources":["../src/iterate-chunks.ts"],"sourcesContent":[null],"names":["MATCH"],"mappings":";;;;;;AAEO,gBAAgB,aAAa,CACnC,IAA0B,EAAA;IAE1B,IAAI,MAAM,GAAiB,EAAE;AAC7B,IAAA,WAAW,MAAM,KAAK,IAAI,IAAI,EAAE;AAC/B,QAAA,IAAI,KAAK,KAAKA,YAAK,EAAE;AACpB,YAAA,MAAM,MAAM;YACZ,MAAM,GAAG,EAAE;QACZ;aAAO;AACN,YAAA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QACnB;IACD;AAEA,IAAA,MAAM,MAAM;AACb;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MATCH } from './search.mjs';
|
|
2
|
+
import 'uint8arrays/concat';
|
|
3
|
+
import 'uint8arrays/from-string';
|
|
4
|
+
|
|
5
|
+
async function* iterateChunks(iter) {
|
|
6
|
+
let chunks = [];
|
|
7
|
+
for await (const value of iter) {
|
|
8
|
+
if (value === MATCH) {
|
|
9
|
+
yield chunks;
|
|
10
|
+
chunks = [];
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
chunks.push(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
yield chunks;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { iterateChunks };
|
|
20
|
+
//# sourceMappingURL=iterate-chunks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterate-chunks.mjs","sources":["../src/iterate-chunks.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAEO,gBAAgB,aAAa,CACnC,IAA0B,EAAA;IAE1B,IAAI,MAAM,GAAiB,EAAE;AAC7B,IAAA,WAAW,MAAM,KAAK,IAAI,IAAI,EAAE;AAC/B,QAAA,IAAI,KAAK,KAAK,KAAK,EAAE;AACpB,YAAA,MAAM,MAAM;YACZ,MAAM,GAAG,EAAE;QACZ;aAAO;AACN,YAAA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QACnB;IACD;AAEA,IAAA,MAAM,MAAM;AACb;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var concat = require('uint8arrays/concat');
|
|
4
|
+
var toString = require('uint8arrays/to-string');
|
|
5
|
+
var iterateChunks = require('./iterate-chunks.cjs');
|
|
6
|
+
require('./search.cjs');
|
|
7
|
+
require('uint8arrays/from-string');
|
|
8
|
+
|
|
9
|
+
async function* iterateStrings(iter) {
|
|
10
|
+
for await (const chunks of iterateChunks.iterateChunks(iter)) {
|
|
11
|
+
yield toString.toString(concat.concat(chunks));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.iterateStrings = iterateStrings;
|
|
16
|
+
//# sourceMappingURL=iterate-strings.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterate-strings.cjs","sources":["../src/iterate-strings.ts"],"sourcesContent":[null],"names":["iterateChunks","toString","concat"],"mappings":";;;;;;;;AAMO,gBAAgB,cAAc,CACpC,IAA0B,EAAA;IAE1B,WAAW,MAAM,MAAM,IAAIA,2BAAa,CAAC,IAAI,CAAC,EAAE;AAC/C,QAAA,MAAMC,iBAAQ,CAACC,aAAM,CAAC,MAAM,CAAC,CAAC;IAC/B;AACD;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { concat } from 'uint8arrays/concat';
|
|
2
|
+
import { toString } from 'uint8arrays/to-string';
|
|
3
|
+
import { iterateChunks } from './iterate-chunks.mjs';
|
|
4
|
+
import './search.mjs';
|
|
5
|
+
import 'uint8arrays/from-string';
|
|
6
|
+
|
|
7
|
+
async function* iterateStrings(iter) {
|
|
8
|
+
for await (const chunks of iterateChunks(iter)) {
|
|
9
|
+
yield toString(concat(chunks));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { iterateStrings };
|
|
14
|
+
//# sourceMappingURL=iterate-strings.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterate-strings.mjs","sources":["../src/iterate-strings.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAMO,gBAAgB,cAAc,CACpC,IAA0B,EAAA;IAE1B,WAAW,MAAM,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE;AAC/C,QAAA,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B;AACD;;;;"}
|
package/lib/iterator.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var search = require('./search.cjs');
|
|
4
|
+
require('uint8arrays/concat');
|
|
5
|
+
require('uint8arrays/from-string');
|
|
6
|
+
|
|
7
|
+
class IteratorStreamSearch {
|
|
8
|
+
_iter;
|
|
9
|
+
_search;
|
|
10
|
+
constructor(needle, _iter) {
|
|
11
|
+
this._iter = _iter;
|
|
12
|
+
this._search = new search.StreamSearch(needle);
|
|
13
|
+
}
|
|
14
|
+
async *[Symbol.asyncIterator]() {
|
|
15
|
+
const it = this._iter[Symbol.asyncIterator]();
|
|
16
|
+
while (true) {
|
|
17
|
+
let result;
|
|
18
|
+
try {
|
|
19
|
+
result = await it.next();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (it.throw) {
|
|
23
|
+
result = await it.throw(error);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (result.done) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
yield* this._search.feed(result.value);
|
|
33
|
+
}
|
|
34
|
+
const tail = this._search.end();
|
|
35
|
+
if (tail.length) {
|
|
36
|
+
yield tail;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.IteratorStreamSearch = IteratorStreamSearch;
|
|
42
|
+
//# sourceMappingURL=iterator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterator.cjs","sources":["../src/iterator.ts"],"sourcesContent":[null],"names":["StreamSearch"],"mappings":";;;;;;MAEa,oBAAoB,CAAA;AAKvB,IAAA,KAAA;AAJD,IAAA,OAAO;IAEf,WAAA,CACC,MAA2B,EACnB,KAAgC,EAAA;QAAhC,IAAA,CAAA,KAAK,GAAL,KAAK;QAEb,IAAI,CAAC,OAAO,GAAG,IAAIA,mBAAY,CAAC,MAAM,CAAC;IACxC;AAEO,IAAA,QAAQ,MAAM,CAAC,aAAa,CAAC,GAAA;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;QAC7C,OAAO,IAAI,EAAE;AACZ,YAAA,IAAI,MAAkC;AACtC,YAAA,IAAI;AACH,gBAAA,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE;YACzB;YAAE,OAAO,KAAK,EAAE;AACf,gBAAA,IAAI,EAAE,CAAC,KAAK,EAAE;oBACb,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC/B;qBAAO;AACN,oBAAA,MAAM,KAAK;gBACZ;YACD;AAEA,YAAA,IAAI,MAAM,CAAC,IAAI,EAAE;gBAChB;YACD;AAEA,YAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACvC;QAEA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;AAC/B,QAAA,IAAI,IAAI,CAAC,MAAM,EAAE;AAChB,YAAA,MAAM,IAAI;QACX;IACD;AACA;;;;"}
|
package/lib/iterator.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StreamSearch } from './search.mjs';
|
|
2
|
+
import 'uint8arrays/concat';
|
|
3
|
+
import 'uint8arrays/from-string';
|
|
4
|
+
|
|
5
|
+
class IteratorStreamSearch {
|
|
6
|
+
_iter;
|
|
7
|
+
_search;
|
|
8
|
+
constructor(needle, _iter) {
|
|
9
|
+
this._iter = _iter;
|
|
10
|
+
this._search = new StreamSearch(needle);
|
|
11
|
+
}
|
|
12
|
+
async *[Symbol.asyncIterator]() {
|
|
13
|
+
const it = this._iter[Symbol.asyncIterator]();
|
|
14
|
+
while (true) {
|
|
15
|
+
let result;
|
|
16
|
+
try {
|
|
17
|
+
result = await it.next();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (it.throw) {
|
|
21
|
+
result = await it.throw(error);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (result.done) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
yield* this._search.feed(result.value);
|
|
31
|
+
}
|
|
32
|
+
const tail = this._search.end();
|
|
33
|
+
if (tail.length) {
|
|
34
|
+
yield tail;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { IteratorStreamSearch };
|
|
40
|
+
//# sourceMappingURL=iterator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterator.mjs","sources":["../src/iterator.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;MAEa,oBAAoB,CAAA;AAKvB,IAAA,KAAA;AAJD,IAAA,OAAO;IAEf,WAAA,CACC,MAA2B,EACnB,KAAgC,EAAA;QAAhC,IAAA,CAAA,KAAK,GAAL,KAAK;QAEb,IAAI,CAAC,OAAO,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC;IACxC;AAEO,IAAA,QAAQ,MAAM,CAAC,aAAa,CAAC,GAAA;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;QAC7C,OAAO,IAAI,EAAE;AACZ,YAAA,IAAI,MAAkC;AACtC,YAAA,IAAI;AACH,gBAAA,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE;YACzB;YAAE,OAAO,KAAK,EAAE;AACf,gBAAA,IAAI,EAAE,CAAC,KAAK,EAAE;oBACb,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC/B;qBAAO;AACN,oBAAA,MAAM,KAAK;gBACZ;YACD;AAEA,YAAA,IAAI,MAAM,CAAC,IAAI,EAAE;gBAChB;YACD;AAEA,YAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACvC;QAEA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;AAC/B,QAAA,IAAI,IAAI,CAAC,MAAM,EAAE;AAChB,YAAA,MAAM,IAAI;QACX;IACD;AACA;;;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var search = require('./search.cjs');
|
|
4
|
+
require('uint8arrays/concat');
|
|
5
|
+
require('uint8arrays/from-string');
|
|
6
|
+
|
|
7
|
+
const EOQ = Symbol("End of Queue");
|
|
8
|
+
class QueueableStreamSearch {
|
|
9
|
+
_search;
|
|
10
|
+
_chunksQueue = [];
|
|
11
|
+
_notify;
|
|
12
|
+
_closed = false;
|
|
13
|
+
constructor(needle) {
|
|
14
|
+
this._search = new search.StreamSearch(needle);
|
|
15
|
+
}
|
|
16
|
+
push(...chunks) {
|
|
17
|
+
if (this._closed) {
|
|
18
|
+
throw new Error("cannot call push after close");
|
|
19
|
+
}
|
|
20
|
+
this._chunksQueue.push(...chunks);
|
|
21
|
+
if (this._notify) {
|
|
22
|
+
this._notify();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
close() {
|
|
26
|
+
if (this._closed) {
|
|
27
|
+
throw new Error("close was already called");
|
|
28
|
+
}
|
|
29
|
+
this._closed = true;
|
|
30
|
+
this._chunksQueue.push(EOQ);
|
|
31
|
+
if (this._notify) {
|
|
32
|
+
this._notify();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async *[Symbol.asyncIterator]() {
|
|
36
|
+
while (true) {
|
|
37
|
+
let chunk;
|
|
38
|
+
while (!(chunk = this._chunksQueue.shift())) {
|
|
39
|
+
await new Promise((resolve) => (this._notify = resolve));
|
|
40
|
+
this._notify = undefined;
|
|
41
|
+
}
|
|
42
|
+
if (chunk === EOQ) {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
yield* this._search.feed(chunk);
|
|
46
|
+
}
|
|
47
|
+
const tail = this._search.end();
|
|
48
|
+
if (tail.length) {
|
|
49
|
+
yield tail;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.QueueableStreamSearch = QueueableStreamSearch;
|
|
55
|
+
//# sourceMappingURL=queueable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queueable.cjs","sources":["../src/queueable.ts"],"sourcesContent":[null],"names":["StreamSearch"],"mappings":";;;;;;AAEA,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC;MAErB,qBAAqB,CAAA;AACzB,IAAA,OAAO;IACP,YAAY,GAAmC,EAAE;AACjD,IAAA,OAAO;IACP,OAAO,GAAG,KAAK;AAEvB,IAAA,WAAA,CAAmB,MAA2B,EAAA;QAC7C,IAAI,CAAC,OAAO,GAAG,IAAIA,mBAAY,CAAC,MAAM,CAAC;IACxC;IAEO,IAAI,CAAC,GAAG,MAAoB,EAAA;AAClC,QAAA,IAAI,IAAI,CAAC,OAAO,EAAE;AACjB,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;QAChD;QAEA,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACjC,QAAA,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,OAAO,EAAE;QACf;IACD;IAEO,KAAK,GAAA;AACX,QAAA,IAAI,IAAI,CAAC,OAAO,EAAE;AACjB,YAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC;QAC5C;AAEA,QAAA,IAAI,CAAC,OAAO,GAAG,IAAI;AACnB,QAAA,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;AAC3B,QAAA,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,OAAO,EAAE;QACf;IACD;AAEO,IAAA,QAAQ,MAAM,CAAC,aAAa,CAAC,GAAA;QACnC,OAAO,IAAI,EAAE;AACZ,YAAA,IAAI,KAA0C;AAC9C,YAAA,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,EAAE;AAC5C,gBAAA,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,MAAM,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC;AAC9D,gBAAA,IAAI,CAAC,OAAO,GAAG,SAAS;YACzB;AAEA,YAAA,IAAI,KAAK,KAAK,GAAG,EAAE;gBAClB;YACD;YAEA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;QAChC;QAEA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;AAC/B,QAAA,IAAI,IAAI,CAAC,MAAM,EAAE;AAChB,YAAA,MAAM,IAAI;QACX;IACD;AACA;;;;"}
|
package/lib/queueable.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Token } from
|
|
2
|
-
export declare class QueueableStreamSearch {
|
|
3
|
-
private _search;
|
|
4
|
-
private _chunksQueue;
|
|
5
|
-
private _notify?;
|
|
6
|
-
private _closed;
|
|
7
|
-
constructor(needle: Uint8Array | string);
|
|
8
|
-
push(...chunks: Uint8Array[]): void;
|
|
9
|
-
close(): void;
|
|
10
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<Token>;
|
|
11
|
-
}
|
|
1
|
+
import { type Token } from "./search.js";
|
|
2
|
+
export declare class QueueableStreamSearch {
|
|
3
|
+
private _search;
|
|
4
|
+
private _chunksQueue;
|
|
5
|
+
private _notify?;
|
|
6
|
+
private _closed;
|
|
7
|
+
constructor(needle: Uint8Array | string);
|
|
8
|
+
push(...chunks: Uint8Array[]): void;
|
|
9
|
+
close(): void;
|
|
10
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Token>;
|
|
11
|
+
}
|