0

I have one Django app and in the view of that I am using gzip_str(str) method to compress data and send back to the browser. Now I want to get the original string back in the browser. How can I decode the string in JS.

P.S. I have found few questions here related to the javascript decode of gzip string but I could not figure out how to use those. Please tell me how can I decode and get the original string.

sveyda
  • 76
  • 2
  • 13
Nilesh
  • 69
  • 1
  • 11
  • Does this answer your question? [Decompress gzip and zlib string in javascript](https://stackoverflow.com/questions/14620769/decompress-gzip-and-zlib-string-in-javascript) – Vladimir Panteleev Feb 10 '20 at 02:21

2 Answers2

0

Serve the string with an appropriate Content-Encoding, then the browser will decode it for you.

Vladimir Panteleev
  • 24,651
  • 6
  • 70
  • 114
-1

There is javascript library called gzip-js you could try this.

var out = gzip.unzip(data, options);
sveyda
  • 76
  • 2
  • 13
  • Thanks for your answer.. Could you please tell me what will be the "options" in case when the data is compressed using gzip_str(str) function. – Nilesh Feb 10 '19 at 14:54
  • if you look at the pull request of this github repository there is a fixed version of the [gzip-js](https://github.com/coolaj86/gzip-js) you can use this version without passing options. – sveyda Feb 10 '19 at 15:39
  • I tried to copy that file and added in my html when I am running the application it is giving error "Uncaught ReferenceError: require is not defined". how to solve this. Exactly which JS file need to included in the html to use the gzip.unzip function. – Nilesh Feb 10 '19 at 18:04
  • According to its documentation, `gzip-js` can only compress, not decompress. – Vladimir Panteleev Feb 10 '20 at 02:22