Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Blob/File stream methods #8

Open
rotu opened this issue Jun 18, 2021 · 3 comments
Open

Missing Blob/File stream methods #8

rotu opened this issue Jun 18, 2021 · 3 comments
Assignees

Comments

@rotu
Copy link

rotu commented Jun 18, 2021

This polyfill works great for streaming fetches, but it doesn't patch the ReadableStream implementation of Blob (and by extension, File).

The following returns a function in Chrome but not in Firefox when using the polyfill:
x=new Blob().stream().pipeThrough

@zenmumbler zenmumbler self-assigned this Jun 22, 2021
@jo
Copy link

jo commented Apr 28, 2022

Thanks for the good work!

Looks like this already has been implemented - any chance to get it released? I'm using the unpkg hosted version at https://unpkg.com/@stardazed/streams-polyfill/dist/sd-streams-polyfill.min.js and there Blob is unpatched on FF

@zenmumbler
Copy link
Member

I made a test implementation indeed, but there's a fundamental problem where this will not just work as a simple method polyfill. Without resorting to terrible page scanning and other hackery there is for example no way to get a patched File back from an <input type="file"> onchange event.

There were some other issues as well but it's been a while but for me not being able to just use a File without calling some wrapper function was a dealbreaker, polyfill-wise.

Also I can't remember how well I tested the Blob modification. I will have to look back at it, but schedule for that is currently undetermined.

@jo
Copy link

jo commented May 1, 2022

Thanks for your response, @zenmumbler! I look forward to it, if something comes once :)

I would like to compress blobs in this way:

blob.stream().pipeThrough(new CompressionStream('gzip'))

which is not yet polyfillable. I use this stupid patch to work around the problem for the time being:

export class PatchableReadableStream extends ReadableStream {
  constructor (reader) {
    super({
      async start(controller) {
        while (true) {
          const { done, value } = await reader.read()
          if (done) break
          controller.enqueue(value)
        }
        controller.close()
        reader.releaseLock()
      }
    })
  }
}

const readableStream = new PatchableReadableStream(blob.stream().getReader())
readableStream.pipeThrough(new CompressionStream('gzip'))

Not pretty, but works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants