@@ -29,54 +29,52 @@ export default class Trix {
2929 const searchWord = firstWord . toLowerCase ( )
3030 const res = await this . getBuffer ( searchWord , opts )
3131
32- if ( res ) {
33- let { end, buffer } = res
34- let done = false
35- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
36- while ( ! done ) {
37- const str = this . decoder . decode ( buffer )
38-
39- // slice to lastIndexOf('\n') to make sure we get complete records
40- // since the buffer fetch could get halfway into a record
41- const lines = str
42- . slice ( 0 , str . lastIndexOf ( '\n' ) )
43- . split ( '\n' )
44- . filter ( f => f )
45-
46- const hits2 = [ ] as string [ ]
47- for ( const line of lines ) {
48- const word = line . split ( ' ' ) [ 0 ]
49-
50- if ( word . startsWith ( searchWord ) ) {
51- hits2 . push ( line )
52- } else if ( word > searchWord ) {
53- // we are done scanning if we are lexicographically greater than
54- // the search string
55- done = true
56- }
57- }
58- const hits = hits2 . flatMap ( line => {
59- const [ term , ...parts ] = line . split ( ' ' )
60- return parts
61- . filter ( elt => elt )
62- . map ( elt => [ term , elt . split ( ',' ) [ 0 ] ] as [ string , string ] )
63- } )
64-
65- resultArr = resultArr . concat ( hits )
66-
67- // if we are done or have filled up maxResults, break
68- if ( done || resultArr . length >= this . maxResults ) {
69- break
32+ let { end, buffer } = res
33+ let done = false
34+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
35+ while ( ! done ) {
36+ const str = this . decoder . decode ( buffer )
37+
38+ // slice to lastIndexOf('\n') to make sure we get complete records
39+ // since the buffer fetch could get halfway into a record
40+ const lines = str
41+ . slice ( 0 , str . lastIndexOf ( '\n' ) )
42+ . split ( '\n' )
43+ . filter ( Boolean )
44+
45+ const hits2 = [ ] as string [ ]
46+ for ( const line of lines ) {
47+ const word = line . split ( ' ' ) [ 0 ]
48+
49+ if ( word . startsWith ( searchWord ) ) {
50+ hits2 . push ( line )
51+ } else if ( word > searchWord ) {
52+ // we are done scanning if we are lexicographically greater than
53+ // the search string
54+ done = true
7055 }
56+ }
57+ const hits = hits2 . flatMap ( line => {
58+ const [ term , ...parts ] = line . split ( ' ' )
59+ return parts
60+ . filter ( Boolean )
61+ . map ( elt => [ term , elt . split ( ',' ) [ 0 ] ] as [ string , string ] )
62+ } )
63+
64+ resultArr = resultArr . concat ( hits )
65+
66+ // if we are done or have filled up maxResults, break
67+ if ( done || resultArr . length >= this . maxResults ) {
68+ break
69+ }
7170
72- // fetch more data
73- const res2 = await this . ixFile . read ( CHUNK_SIZE , end , opts )
74- if ( res2 . length === 0 ) {
75- break
76- }
77- buffer = concatUint8Array ( [ buffer , res2 ] )
78- end += CHUNK_SIZE
71+ // fetch more data
72+ const res2 = await this . ixFile . read ( CHUNK_SIZE , end , opts )
73+ if ( res2 . length === 0 ) {
74+ break
7975 }
76+ buffer = concatUint8Array ( [ buffer , res2 ] )
77+ end += CHUNK_SIZE
8078 }
8179 }
8280
@@ -94,7 +92,7 @@ export default class Trix {
9492 } )
9593 const result = file
9694 . split ( '\n' )
97- . filter ( f => f )
95+ . filter ( Boolean )
9896 . map ( line => {
9997 const p = line . length - ADDRESS_SIZE
10098 const prefix = line . slice ( 0 , p )
0 commit comments