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

Provide access to receivedBytes and totalBytes #31

Open
davej opened this issue Oct 27, 2017 · 9 comments
Open

Provide access to receivedBytes and totalBytes #31

davej opened this issue Oct 27, 2017 · 9 comments

Comments

@davej
Copy link

davej commented Oct 27, 2017

Perhaps in the onProgress handler? It could receive a second parameter with a details object. The signature could look something like this:

{
  receivedBytes,
  totalBytes,
  item,
}

Further expanding on this idea, it could also include useful info like eta (estimated time remaining in milliseconds) and bps (current bytes per second). These would be handy but are less important as they can be calculated outside of the module using receivedBytes, totalBytes and a setTimeout.

@sindresorhus
Copy link
Owner

Sure. Let's just make it a breaking change and include the percentage in the object too and make it the first argument.

Pull request welcome :)

@davej
Copy link
Author

davej commented Oct 30, 2017

Cool. Yes to eta and bps too?

@sindresorhus
Copy link
Owner

Yes, but with more verbose names.

@davej
Copy link
Author

davej commented Oct 30, 2017

Ok, might make the download stats stuff a separate module and reuse that. Sound ok?

@sindresorhus
Copy link
Owner

Sure

@davej
Copy link
Author

davej commented Nov 1, 2017

Started on this and created a lib for it: https://github.com/DaveJ/transfer-stats
Should the onProgress arg be a Set containing all transfers?

Any thoughts on testing this within the context of electron-dl?

@sindresorhus
Copy link
Owner

Should the onProgress arg be a Set containing all transfers?

For electronDl([options]) yes, but for electronDl.download(window, url, [options]) it should just be that specific transfer.

Any thoughts on testing this within the context of electron-dl?

You could do mostly something like this test:

test('Download a single file', async t => {

@davej
Copy link
Author

davej commented Nov 4, 2017

Thanks. The problem I've found with that test is that updated only seems to get called once (when progress is at 0 bytes). Perhaps that's OK and we can rely on manual testing to make sure progress works? transfer-stats is pretty well tested.

@sindresorhus
Copy link
Owner

@davej Yeah, that should be fine.

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

No branches or pull requests

2 participants