MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / parseCSV

Function parseCSV

frontend/src/hooks/stream/useStreamingCSVParser.ts:309–343  ·  view source on GitHub ↗
(
    file: File,
    options: {
      batchSize?: number;
      delimiter?: string;
      onChunkParsed?: (chunk: string[][], headers: string[], isFirstChunk: boolean) => Promise<void>;
      onProgress?: (progress: number, stats: StreamingCSVParseStats) => void;
      sampleRowsLimit?: number;
    } = {}
  )

Source from the content-addressed store, hash-verified

307 * Main function to parse a CSV file
308 */
309 const parseCSV = async (
310 file: File,
311 options: {
312 batchSize?: number;
313 delimiter?: string;
314 onChunkParsed?: (chunk: string[][], headers: string[], isFirstChunk: boolean) => Promise<void>;
315 onProgress?: (progress: number, stats: StreamingCSVParseStats) => void;
316 sampleRowsLimit?: number;
317 } = {}
318 ): Promise<CSVParseResult> => {
319 try {
320 setIsLoading(true);
321 setError(null);
322 setProgress(0);
323
324 // Stream the file
325 const fileStream = file.stream();
326
327 // Parse the stream
328 const result = await parseCSVStream(fileStream, {
329 ...options,
330 estimatedTotalBytes: file.size,
331 onComplete: (result) => {
332 result.fileName = file.name;
333 }
334 });
335
336 return result;
337 } catch (err) {
338 const errorMessage = err instanceof Error ? err.message : 'Unknown error parsing CSV';
339 setError(errorMessage);
340 setIsLoading(false);
341 throw err;
342 }
343 };
344
345 /**
346 * Parse a small fragment of CSV text directly

Callers

nothing calls this directly

Calls 2

parseCSVStreamFunction · 0.85
streamMethod · 0.80

Tested by

no test coverage detected