Skip to content

Commit f30a212

Browse files
committed
now using pako for decompression
1 parent d8fd7a5 commit f30a212

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/lib/geodata.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Loki from 'lokijs';
22
import ngeohash from 'ngeohash'; // Import ngeohash for better performance
3+
import pako from 'pako';
34
const 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);

0 commit comments

Comments
 (0)