jimmywarting / native-file-system-adapter

File system, based on the spec reference implementation

Home Page:https://jimmywarting.github.io/native-file-system-adapter/example/test.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: "save-file" cancel handling

PaulTime opened this issue · comments

Hello, I search for some way to catch the cancel download event

const { chooseFileSystemEntries } = await import('services/native-file-system-adapter/src/es6');

    const fileHandle = await chooseFileSystemEntries({
      type: 'save-file',
      accepts: [
        { extensions: [name.split('.').pop()] },
        { mimeTypes: [type] },
      ],
      excludeAcceptAllOption: true,
      _preferPolyfill: false,
      _name: name,
    });

    const writable = await fileHandle.createWritable();

    const body$ = await fetch(url, { credentials: 'include' }).then(res => res.body);

    const { data: decrypted$ } = await openpgp.decrypt({
      message: await openpgp.message.read(body$),
      passwords: randomKey,
      format: 'binary',
      streaming: 'web',
    });

    await decrypted$.pipeTo(writable);

here is my code
and for now I don't see any way to catch or subscribe to this event

When the native file system is in use (or saving a file using without the help of service worker) then there is no visual operations that you are writing something to the disc. so there is no way to "cancel" unless you provide them with a mean to stop the process yourself with the help of AbortSignal.

but if you are using _preferPolyfill: false and takes advantage of service worker then it's possible to cancel the writing from the browsers UI, this can be trickier to catch since chrome don't delegate the abort event back so well. it it's even more trickier when transferable streams are not supported since it's harder to pipe the data flow from main thread to the service worker and vice versa

I understand) maybe its better to just leave it as it is for now) because I also have had the same thoughts on this.
Hope that native-file-system will land by the end of this year in stable build.

I'm working on adapting https://github.com/MattiasBuelens/remote-web-streams/ so it will be possible to detect a cancel event

I have been able to detect when FF cancel now (not commited)
chrome still lacks notification... see & star this bug: https://bugs.chromium.org/p/chromium/issues/detail?id=638494

as of now chrome will pull data as long as the underlying bucket isn't full
this means that chrome will pull a few KiB even if the the download stream is canceled or paused. but at least it will signal a backpressure now.

fixed now