Nisha Patel
Problem
I have a problem which I can't understand.
I'm trying to decompress a base64 string with zlib in javascript (Nodejs)
but it throws me an error
Process finished with exit code 0
do I need to add something more?
am I doing something wrong?
What I understand is that the Windows size bits is wrong, but javascript doesn't allow negative windows as Python allows
Thanks to all
In Python I have de following script to decompress some data from base64 and it works well
the result is something like this
Solution
Use inflateRawSync instead of inflateSync. Then it will work.
(By the way: I thought unzipSync should also work, given its description below, but for some reason, unzipSync throws Error: incorrect header check too.)
References:
From >https://nodejs.org/api/zlib.html:
zlib.inflateRawSync(buffer[, options]): Decompress a chunk of data with InflateRaw.
Class: zlib.InflateRaw: Decompress a raw deflate stream.
zlib.unzipSync(buffer[, options]): Decompress a chunk of data with Unzip.
Class: zlib.Unzip: Decompress either a Gzip- or Deflate-compressed stream by auto-detecting the header.
From >https://docs.python.org/3/library/zlib.html:
The wbits parameter controls the size of the history buffer (or “window size”), and what header and trailer format is expected. It is similar to the parameter for compressobj(), but accepts more ranges of values:
+8 to +15: The base-two logarithm of the window size. The input must include a zlib header and trailer.
0: Automatically determine the window size from the zlib header. Only supported since zlib 1.2.3.5.
−8 to −15: Uses the absolute value of wbits as the window size logarithm. The input must be a raw stream with no header or trailer.
+24 to +31 = 16 + (8 to 15): Uses the low 4 bits of the value as the window size logarithm. The input must include a gzip header and trailer.
+40 to +47 = 32 + (8 to 15): Uses the low 4 bits of the value as the window size logarithm, and automatically accepts either the zlib or gzip format.
Answered by: >Tomi
Credit: >StackOverflow
Blog Links:
>Sorting the restframework in Django
>Ways to access instances of models in view in order to save both forms at once in Django
>What makes index.html have such kind of name in Django?
>Fix Module Not Found during Deployment- Django
>Creating a Django with existing directories, files, etc.?
>How to Read a CSV file with PHP using cURL?