-
-
Notifications
You must be signed in to change notification settings - Fork 282
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
Switch from downloadjs to multi-download #174
Conversation
Version 3.0.0 ⚡️🚀
- docker-compose version 1.29.2, build unknown - Linux 5.15.0-1029-oracle blenderskool#35-Ubuntu SMP Tue Jan 24 15:17:52 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ``` ERROR: The Compose file './docker-compose.yml' is invalid because: services.blaze-server.environment.TRUST_PROXY contains true, which is an invalid type, it should be a string, number, or a null ```
fix: docker-compose now
Version 3.0.1 🔨
Universal Analytics has been shut down
const download = async (file) => { | ||
const a = document.createElement('a'); | ||
a.download = file.name; | ||
a.href = URL.createObjectURL(file); | ||
a.style.display = 'none'; | ||
document.body.append(a); | ||
a.click(); | ||
|
||
// Chrome requires the timeout | ||
await delay(100); | ||
a.remove(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use downloadjs
for this? From what I can see, delay of 1s is something that is to be added for fixing the issue. The individual file download seems to use same process as downloadjs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in addition to the 1s delay, to me it looks like this additional 100ms delay before removing the a
again is not present in downloadjs. it looks like they immediately remove it after clicking: https://github.com/rndme/download/blob/09d6492f47ef18feca39c3d748960dce44f93a89/download.js#L116-L117
maybe chrome introduced the need for this additional short delay somewhere in the last 8 years (the latest release of downloadjs)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say this is a nice elimination of some legacy/unmaintained code, in exchange for a download
function that's only 10 lines without dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see the timeout. Changes seems fine to me, I'll also test it on my end in couple of browsers to ensure that it doesn't break existing flows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK! we might be able to reduce the 1000ms, I blamed it to a commit related to cross-origin URLs sindresorhus/multi-download@bf7580d#r144977818
}); | ||
multiDownload( | ||
// make regular File from webtorrent File https://github.com/webtorrent/webtorrent/blob/v2.4.14/lib/file.js#L7 | ||
files.map(file => new File([file.getBlob()], file.name, {type: file.type})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, it looks like File.getBlob
was removed in webtorrent v2.
this seems related to them switching to local storage in v2 as opposed to keeping complete torrents in memory in v1 ref webtorrent/webtorrent#86 (comment)
edit: they now have File.blob
to load the whole torrent into memory and (more interestingly) File.streamURL
(requires client.createServer
to be ran beforehand).
Maybe blaze can even get rid of download.js
altogether using the local storage functionality of webtorrent v2 🤔
they use this PR was superceded againFileSystemDirectoryHandle
ref webtorrent/webtorrent#2208
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blaze currently uses Webtorrent v1, and we'll need to upgrade to v2. From what I can recall since the last time I had checked, there were a bunch of API changes associated with v2 that we'd also have to make in Blaze which I wasn't fond of picking up then. Would you be interested in picking this up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'm also afraid it's a can of worms... the local storage feature might make it worthwhile though. I guess a 10GB file would now fill up 10GB of my swap right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
judging by the File API docs, I think using streamURL you can initiate a download before the torrent has finished downloading, and so download.js could theoretically be called upon as soon as the torrent is initiated.
most importantly, that way the file doesn't need to go fully into memory in a Blob in order to send to downloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file.getBlob and file.blob are functionally identical, it was simply renamed to match the W3C file API, rather than create our own structure, but getBlob also loaded the entire file into memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah just saw your cross comment, so file.streamURL
is a viable option to get around the 'whole file in memory' pattern in the current downloading setup, with minimal overhead from client.createServer
. that's great to hear and probably the way to move forward there!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the local storage feature might make it worthwhile though
@ddelange isn't the local storage limited to like 10MBs? I wonder how it would manage files of much higher sizes in such a limited space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in v2 the torrents directly download to /tmp/webtorrent
by default using file system access.
path
can be set on a per-torrent basis by the receiver before the torrent is added (folder selection is google chrome only if I understood the comments correctly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in v2 the torrents directly download to /tmp/webtorrent by default using file system access.
for the sake of simplicity lets say sure, but if you want specifics, it actually writes to individual chunks via FSA's origin private file system, which functionally is no different from the likes of localStorage or IDB, except its a LOT faster, and allows for MUCH, MUCH, MUCH bigger file sizes, in extreme cases up to terabytes
on chrome that's a bit different, because IF YOU CHOOSE TO specify a rootDir, it can emulate the file structure in a specified folder as already mentioned, on top of saving chunks as cache to OPFS
that's the big difference for webtorrent v2, the storage and interfaces it provides:
- createServer now provides insanely powerful, 0 overhead methods for rendering media like video, text, images using browser's own tools, instead of implementing custom tooling for it, which also allows other libraries to consume what webtorrent creates as its exposed via plain URL
- storage isn't now memory, so we're no longer at the poor sub 2GB file limit, the most I could get webtorrent to store now is ~2TB after which chrome stopped enjoying handling so much data and started erroring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webtorrent v2 aside, @blenderskool did you get a chance to test more than 10 files? |
@ddelange Not yet, will check it tomorrow. By the way, are you done with the changes for this PR? |
I'd say ready for review again yeah :) |
hi @blenderskool, did you get a chance to test more than 10 files with this fix? |
hi @blenderskool 👋 friendly reminder:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ddelange Finally got some time to test the changes. I don't know if it's just me but I see following errors with just a single file! Have you tested your changes?
@ddelange I've pushed some fixes to your code and I can now see the multi-file(and single-file) download to work. Do test it from your end too if it is working as expected. |
awesome, your changes look clean! |
Co-authored-by: ddelange <[email protected]>
ready for merge from my side 👍 |
Fix #163