(
file: File,
options: {
batchSize?: number;
delimiter?: string;
onChunkParsed?: (chunk: string[][], headers: string[], isFirstChunk: boolean) => Promise<void>;
onProgress?: (progress: number, stats: StreamingCSVParseStats) => void;
sampleRowsLimit?: number;
} = {}
)
| 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 |
nothing calls this directly
no test coverage detected