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

Transferring blobs / binary data #381

Closed
nanomonkey opened this issue Oct 21, 2020 · 5 comments
Closed

Transferring blobs / binary data #381

nanomonkey opened this issue Oct 21, 2020 · 5 comments

Comments

@nanomonkey
Copy link

Many thanks for Sente, I've been happily using it for some time.

Are there any examples of sending and receiving binary files, such as images or database blobs? I'm unsure if there is a more appropriate route than base64 encoding/decoding. Is it possible to open up a binary websocket for such messages?

Thanks again!

@ptaoussanis
Copy link
Member

Hey there, apologies for the slow response!

Sente unfortunately doesn't currently provide anything specifically for binary messages out-the-box.
Haven't given it much thought, would be open to seeing ideas/PRs 👍

Otherwise base64 would be one option in the meantime.

Cheers!

@ptaoussanis ptaoussanis changed the title Example of transfering blobs? Transferring blobs / binary data Jan 21, 2021
@awb99
Copy link

awb99 commented Jul 21, 2021

Binary blobs would be cool. Especially when sending larger payload data there is a significant overhead with the encoding. Now that say Apache aeriw can be sent as blobs via http get it would be cool to be able to send them via sente websocket as well.

@rosejn
Copy link
Contributor

rosejn commented Jan 19, 2022

Hi, so I've implemented binary support, and unlike some of the previous discussions around what this would take, it only required minor modifications of about 10 lines of code, not including the packers. I'm using this with msgpack in both Clojure and Clojurescript, and I've extended it to work with typed arrays on both ends, while also supporting all of the Clojure data structures and base value types in binary form. Binary blobs, files, or anything else would be trivial to add. For now though, I'd like to try to get these modifications accepted, and then I'm happy to also contribute the msgpack implementation if you'd like to include that in sente. Those require 2 external libraries, although if I get the time I'd like to unify them and make a new msgpack.cljc library that cleanly implements it once and for all. We needed this ASAP for a product release though, so for now here we are.

Here's the whole diff:
rosejn@3de8274

In short, the current code wraps the string to transmit over the wire with an optional + or - and a callback UUID in case the user hopes for an RPC style reply. That was the only code which relied on the msg being a string. I changed that to instead wrap the msg in a clojure vector which does the same thing, except this way the packers are totally responsible for serialization. If you have thoughts on another approach I'm happy to modify this. Thanks for Sente,

@ptaoussanis
Copy link
Member

@rosejn Thanks Jeff, that sounds promising! Would be very happy to see a PR. Just a heads-up that I'd only expect to review+merge next time I'm doing some batched work on Sente.

Cheers!

@ptaoussanis
Copy link
Member

Closing since #398 is now merged and available on Clojars as [com.taoensso/sente "1.17.0-RC2"] 👍

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

4 participants