File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 11import Loki from 'lokijs' ;
22import ngeohash from 'ngeohash' ; // Import ngeohash for better performance
3+ import pako from 'pako' ;
34const basePath = import . meta. env . BASE_URL ;
45// Initialize a LokiJS database
56
@@ -74,16 +75,14 @@ export async function loadCsvGzFile(url) {
7475 }
7576
7677 // Parse CSV directly from response text
78+ const buffer = await response . arrayBuffer ( ) ;
7779 try {
78- const csvText = await response . text ( ) ;
79- const rows = parseCsv ( csvText ) ;
80- return rows ;
81- } catch {
82- // If text parsing fails, try gzip
83- const blob = await response . blob ( ) ;
84- const decompressed = await new Response ( blob . stream ( ) . pipeThrough ( new DecompressionStream ( 'gzip' ) ) ) . text ( ) ;
85- const rows = parseCsv ( decompressed ) ;
86- return rows ;
80+ const decompressed = pako . inflate ( new Uint8Array ( buffer ) , { to : 'string' } ) ;
81+ return parseCsv ( decompressed ) ;
82+ } catch ( err ) {
83+ // If decompression fails, treat as plain text
84+ const text = new TextDecoder ( ) . decode ( buffer ) ;
85+ return parseCsv ( text ) ;
8786 }
8887 } catch ( error ) {
8988 console . error ( `Error loading data from ${ url } :` , error ) ;
You can’t perform that action at this time.
0 commit comments