Make parse accept ReadableStream<Uint8Array>
parse seems to be the main working horse, it would be great to have the API to work with the ReadableStream as the source to allow for both File or any other types of streams.
Something along these lines:
export async function* parse(
readable: ReadableStream<Uint8Array>,
options?: ParseOptions,
): AsyncGenerator<Node, Node | void, void> {
const document = new Node("@document");
try {
const init = { ...options?.fetchOptions };
if (options?.signal) {
init.signal = options.signal;
}
const stream = readable.pipeThrough(new XMLStream(), {
signal: options?.signal,
});
This is a good idea thanks.
It is already possible to use a file URL like:
parse('file:///path/to/file.xml');
but yes I agree also accepting a ReadableStream makes sense. I'll work on it this week.
Just tried that, it's quite hectic to form the path properly :D
But yes, I can confirm file://.... works as if it's a web resource.
Yeah paths can be a bit confusing! This gets passed to fetch which in Deno accepts http: file: and even data: URLs.
I've started a new branch and draft PR for this feature. I'll need to do more testing but the basic idea works.
This is now implemented in v0.6.0. Apologies for taking so long!
Thank you! This is awesome