2

Please can anyone point me in the right direction for compressing a (quite long) string of text in C# and then decompress it in JavaScript?

Basically I'm encoding an image to base64 and then sending it via a websocket to JavaScript, but want to be able to reduce the size of the string before sending it.
I know of ways it can be done from C# to C#, like using gzip or quicklz, but haven't found anything for C# to JavaScript. Would appreciate any info you have. :) Thanks.

5
  • Wouldn't it take more bandwidth to write a javascript program to decompress the input than to just send the input as uncompressed ascii? Commented Aug 21, 2012 at 14:49
  • 2
    Out of interest, any reason not to return it as a binary image with content- or transfer-encoding? Commented Aug 21, 2012 at 14:50
  • 1
    Just use the HTTP gzip compression, it will do the work for you. Commented Aug 21, 2012 at 14:51
  • Don't know if this will be able to uncompress the string compressed by C#, but there is an Open source JS lib called JSZip Commented Aug 21, 2012 at 14:52
  • My first choice was to send the image bytes instead of converting it to a base64 string, but I lack to know-how to do it. In fact, my previous question was asking how - so if anyone knows, I would appreciate a answer on it :) stackoverflow.com/questions/12041851/… Commented Aug 21, 2012 at 15:59

2 Answers 2

2

Basically I'm encoding an image to base64 and then sending it via a websocket to JavaScript, but want to be able to reduce the size of the string before sending it.

Images are almost always compressed anyway, so I wouldn't expect you to be able to get any benefit there. It strikes me that the main thing you could try to do is remove the "text" part here, avoiding converting to/from base64 in the first place.

I don't have any experience with websockets myself, but I would investigate transferring binary data that way instead of text.

Sign up to request clarification or add additional context in comments.

Comments

1

There seems to be a library for that, but I haven't tried it though: zip.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.