-
Notifications
You must be signed in to change notification settings - Fork 369
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
Some suggestion #13
Comments
You are right, this is just needed if we want to report the download progress. Do you know a better way to report progress and not call the main thread on every chunk? |
Nope, sry. bgFetch.addEventListener('progress', () => {
// If we didn't provide a total, we can't provide a %.
if (!bgFetch.downloadTotal) return;
const percent = Math.round(bgFetch.downloaded / bgFetch.downloadTotal * 100);
console.log(`Download progress: ${percent}%`);
}); but i don't think i would bother with it... For library author i think it's useful to think more of a onion architecture. Try to develop your package with as little dependencies or knowledge of the platform you are running your code on, try to think as if your module was running on a sandboxed enviorment (or web worker, deno, node or bun.js) with no filesystem or network access, or no access to node or browser API's. The core layer of your application should be like a stdin and stdout. How the consumer reads and saves data should be entirely up to the the developers using your package. I might not want or need to use every feature a library brings to the table. then it becomes a js fatigue. It's not hard or annoying to just do the fetching of blob's yourself. fetch(req)
.then(res => res.blob())
.then(imglyRemoveBackground)
.then(done) blob's can come from any place like |
I kind of agree in general. However, in terms of this library you would have to prefetch the wasm files as well as onnx files all as separate blobs and pass it to the js library. One workaround would be to pass |
should have removed this if check as well - if (config.progress)
config.progress(`fetch:${key}`, receivedLength, contentLength); |
https://github.com/imgly/background-removal-js/blob/7b074703ac1c322a10fb551dd7d6e46a2705d4e4/src/bundle.ts#L86C1-L128C2
i think this could be better replaced with this:
there are some advantages to using native method instead of calling the main thread for each and every chunk while streaming.
calling eg
response.blob()
instead of usingresponse.arrayBuffer()
text or using the response.body.getReader can also have some advantages as it can optimize what it should do with the blob.The text was updated successfully, but these errors were encountered: