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

feat: streams in browser #116

Merged
merged 4 commits into from Nov 27, 2019

Conversation

AuHau
Copy link
Contributor

@AuHau AuHau commented Nov 13, 2019

I present you patch that allows usage of downloadDirectory and downloadObservable in browsers.

I was fighting a lot with readable-streams in browsers as there was some problem of proto-chain in Duplex streams. It seems that rollup is to blame for bad bundling. I switched it to webpack and it works as expected. Is that a problem?

I switched it only in the swarm-browser bundle and kept rollup in the timeline build. Should I unify it to webpack? From bundle size there was around 10kb increase in the production build to 242kB.

@AuHau AuHau force-pushed the feat/browser_api_refinment branch 2 times, most recently from bac02e1 to a808810 Compare November 13, 2019 19:16
@AuHau
Copy link
Contributor Author

AuHau commented Nov 14, 2019

Since there is downloadObservable as part of general API, maybe there could be downloadReadableStream() which would expose readable-stream's Readable interface?

Btw. not sure why the second build of Travis is failing. Local tests are working for me. Do you might have some pointers about what is wrong?

Copy link
Collaborator

@PaulLeCam PaulLeCam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR!

I restarted the macOS build but it's taking forever, might be an issue with Travis. It passes on Linux anyways so I don't think it's caused by your changes.

Do you have more details about the issue using rollup please? Is this a known bug?
If it can't be worked around I think it's better to use webpack for the timeline package as well but I'd rather avoid changing tooling to accommodate individual features.

Regarding adding downloadReadableStream(), what would be the use case please?

__tests__/browser.ts Show resolved Hide resolved
__tests__/browser.ts Show resolved Hide resolved
__tests__/browser.ts Show resolved Hide resolved
docs/api-bzz.md Outdated Show resolved Hide resolved
packages/api-bzz-browser/src/index.ts Show resolved Hide resolved
packages/api-bzz-browser/src/utils.ts Outdated Show resolved Hide resolved
packages/swarm-browser/webpack.config.js Outdated Show resolved Hide resolved
@AuHau
Copy link
Contributor Author

AuHau commented Nov 14, 2019

Great!

Well there are several pointers for discussion about rollup and readable-streams. I wish I googled for them earlier than now 😂

Also regarding the uploadFileStream(), in the end I did not move it to the browser implementation because there is no native support in browsers for WritableStreams and requests. It can be emulated like for example this library does: https://github.com/hugomrdias/iso-stream-http/blob/master/lib/request.js

But it only will bring compability with streams, yet it won't bring their actual advantage. Should I add it anyhow in order to unify the browser/Node API more?

Regarding the downloadReadableStream the use-case is mainly being able to utilize stream support of other libraries and the whole (nodejs) ecosystem. I know that Observable is in concept the same, but it does not have such support of libraries...

@PaulLeCam
Copy link
Collaborator

Thanks for the insights, the rollup/readable-streams seems like a real can of worms so better switch to webpack as you did. Could you also switch to webpack in the timeline package please so it's more consistent?

Regarding uploadFileStream() makes sense, can you remove the change in docs/api-bzz.md then please?

Adding downloadReadableStream() sounds like a good idea, maybe it could simply be named downloadStream() as it can only be readable anyways?
Could you please add tests to cover the behaviour both for raw files and manifests if you add this method?

Thanks!

@AuHau
Copy link
Contributor Author

AuHau commented Nov 14, 2019 via email

@PaulLeCam
Copy link
Collaborator

Thanks!

@AuHau AuHau force-pushed the feat/browser_api_refinment branch 2 times, most recently from 8c2f42a to 3207ef0 Compare November 19, 2019 17:26
@AuHau
Copy link
Contributor Author

AuHau commented Nov 19, 2019

So here I present you another version :-D

I added the stream support as discussed. Tests are passing, webpack integrated, docs written.

Let me know your thoughts!

__tests__/browser.ts Show resolved Hide resolved
packages/api-bzz-base/src/index.ts Outdated Show resolved Hide resolved
packages/api-bzz-react-native/src/index.ts Outdated Show resolved Hide resolved
start_swarm_node.sh Show resolved Hide resolved
@PaulLeCam
Copy link
Collaborator

@vujevits if you have the chance could you please review this PR?
I'm mostly wondering if this could affect the React-Native variant in a bad way? Does RN support node streams?

@vmaark
Copy link
Contributor

vmaark commented Nov 25, 2019

@PaulLeCam seems like readable-streams had a related an issue and it's closed, so I suppose it should work. nodejs/readable-stream#319

@PaulLeCam
Copy link
Collaborator

@vujevits OK perfect, thanks for the feedback!

@AuHau
Copy link
Contributor Author

AuHau commented Nov 25, 2019

So here is hopefully last version :-)

@PaulLeCam
Copy link
Collaborator

@AuHau CI is failing because of ESLint issues, could you run yarn lint:fix to address them please?

@AuHau
Copy link
Contributor Author

AuHau commented Nov 25, 2019

Fixed (MacOS still runs as always)

Copy link
Collaborator

@PaulLeCam PaulLeCam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the changes!

@PaulLeCam PaulLeCam merged commit aa9b379 into MainframeOS:master Nov 27, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants