Skip to content

Commit eaf7a53

Browse files
committed
Avoid range beyond
1 parent c343997 commit eaf7a53

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export default class Trix {
3737
let { end, buffer } = res
3838
let done = false
3939
const decoder = new TextDecoder('utf8')
40+
41+
let size: number | undefined
42+
try {
43+
size = (await this.ixFile.stat()).size
44+
} catch (e) {
45+
/* do nothing */
46+
}
47+
4048
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
4149
while (!done) {
4250
let foundSomething = false
@@ -74,6 +82,11 @@ export default class Trix {
7482
// if we are not done, and we haven't filled up maxResults with hits yet,
7583
// then refetch
7684
if (resultArr.length + hits.length < this.maxResults && !done) {
85+
if (size !== undefined && end > size) {
86+
resultArr = resultArr.concat(hits)
87+
break
88+
}
89+
7790
const res2 = await this.ixFile.read(CHUNK_SIZE, end, opts)
7891

7992
// early break if empty response

0 commit comments

Comments
 (0)