( filePath: string, callbacks: Omit<StreamParseOptions, 'filePath'>, formatId?: string )
| 338 | * @param formatId 可选,指定格式 ID(用于 fallback 机制,跳过自动检测) |
| 339 | */ |
| 340 | export async function streamParseFile( |
| 341 | filePath: string, |
| 342 | callbacks: Omit<StreamParseOptions, 'filePath'>, |
| 343 | formatId?: string |
| 344 | ): Promise<void> { |
| 345 | const { onProgress, onMeta, onMembers, onMessageBatch, onLog, batchSize = 5000, formatOptions } = callbacks |
| 346 | |
| 347 | // 根据是否指定 formatId 选择解析方式 |
| 348 | const generator = formatId |
| 349 | ? parseFileWithFormat(formatId, { filePath, batchSize, formatOptions, onProgress, onLog }) |
| 350 | : parseFile({ filePath, batchSize, formatOptions, onProgress, onLog }) |
| 351 | |
| 352 | for await (const event of generator) { |
| 353 | switch (event.type) { |
| 354 | case 'meta': |
| 355 | onMeta(event.data) |
| 356 | break |
| 357 | case 'members': |
| 358 | onMembers(event.data) |
| 359 | break |
| 360 | case 'messages': |
| 361 | onMessageBatch(event.data) |
| 362 | break |
| 363 | case 'progress': |
| 364 | onProgress(event.data) |
| 365 | break |
| 366 | case 'error': |
| 367 | throw event.data |
| 368 | } |
| 369 | } |
| 370 | } |
no test coverage detected