xml-streamify icon indicating copy to clipboard operation
xml-streamify copied to clipboard

Make parse accept ReadableStream<Uint8Array>

Open king8fisher opened this issue 1 year ago • 4 comments

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.

king8fisher avatar Mar 11 '24 15:03 king8fisher

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,
    });

king8fisher avatar Mar 11 '24 15:03 king8fisher

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.

dbushell avatar Mar 11 '24 20:03 dbushell

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.

king8fisher avatar Mar 11 '24 21:03 king8fisher

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.

dbushell avatar Mar 12 '24 08:03 dbushell

This is now implemented in v0.6.0. Apologies for taking so long!

dbushell avatar Jul 26 '24 07:07 dbushell

Thank you! This is awesome

king8fisher avatar Sep 08 '24 01:09 king8fisher