Pass progress as percentage to onUpdate callback
Opened this issue · 0 comments
Currently, the onUpdate callback is called with a progress
parameter, which represents the number of parsed lines.
When implementing a GUI, I might want to display the loading state using a determinate progress bar/spinner including a percentage. It would be great, if the onUpdate callback would give me a progress object, such as
interface Progress {
lines: number;
percentage?: number;
}
where percentage
is a number between 0-1 if it is known (undefined otherwise). This should work for all local file types, such as Blob
or ArrayBuffer
, since the size is already known when starting to parse. Remote streams should work as well, if the Content-Length
header is set.
But actually, the percentage would depend on the number of parsed bytes rather than parsed lines, since the size of a buffer or the Content-Length header indicate the byte length. Therefore, the interface should probably be
interface Progress {
bytes: number;
lines: number;
percentage?: number;
}
or maybe even
interface Progress {
bytes: number;
lines: number;
percentage?: number;
totalBytes?: number;
}
for completeness.