0

I have Numpy Array of floats which I compress using zlib and store in database. Then I want to send compressed data over HTTP and decompress on client side using JavaScript. How can I do it? I am compressing data using below code:

import numpy as np
import zlib

compressedData = zlib.compress(np.array([1.5, 2.5, 1.0]))

I can simply decompress in in python using:

import numpy as np
import zlib

decomrpessedData = np.fromstring(zlib.decompress(compressedData), np.float) 

But how can I decompress it in JS? I tried pako but without success. Is it wrong approach? Should I compress array using some other library?

Michael280
  • 48
  • 10
  • Another way to think about satisfying this requirement is to decompress the array into JSON or equivalent, then ingest it with JS using plain AJAX but ensure that gzip compression is enabled on your web server. https://stackoverflow.com/questions/55171628/using-ajax-to-request-gzip-compressed-data – bfeist Jul 03 '20 at 14:18
  • But I am getting this data from Web API, not from my web server – Michael280 Jul 03 '20 at 19:58
  • @bfeist any other idea? I can do it that way but in this approach I need to first decompress data (data is stored in DB in compressed format) and then compress is again (Web Server will do it) before sending in response – Michael280 Jul 08 '20 at 22:31
  • If you can't get zlib working in javascript, I'd try making the API call from your server on the server side using python or something, then get the data to the browser from your own server. – bfeist Jul 09 '20 at 23:05
  • @bfeist I did it and it works fine but I am not satisfied with it :/ For now I will leave it as it is – Michael280 Jul 21 '20 at 13:22
  • Kudos for pressing on! – bfeist Jul 22 '20 at 14:52

0 Answers0