question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Binary gzip string not in correct gzip format

See original GitHub issue

var output = pako.gzip(“{test:‘hello world’}”, { to: ‘string’ });

fs.writeFile("./gzip-test.txt", output, function(err) {
  if(err) {
    return console.log(err);
  }

  console.log("The file was saved!");
});

Produces this output in a file:

1F C2 8B 08 00 00 00 00 00 00 03 C2 AB 2E 49 2D 2E C2 B1 52 C3 8F 48 C3 8D C3 89 C3 89 57 28 C3 8F 2F C3 8A 49 51 C2 AF 05 00 37 C2 90 12 C3 89 14 00 00 00

According to this:

http://en.wikipedia.org/wiki/Gzip

The output should start with a 1F 8B. It has a C2 in there, otherwise it looks good. I am trying to gzip a big block of JSON in the browser and send it to the backend. The Java backend is throwing an error saying that this is not in GZip format.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
patrickliechtycommented, Apr 16, 2015

I had the same issue when trying to send the data to the server from the browser. I fixed it by doing this:

    headers["Content-Encoding"] = "gzip";
    var gzippedJson = gzip.gzip("{test:'hello world'}");
    //If you use charset=x-user-defined-binary it just sends the data through as is.
    //  If you don't do this, it uses utf-8 which adds extra characters and thus is not in gzip format
    var gzippedBLob = new Blob([gzippedJson], {type: "application/json; charset=x-user-defined-binary"});
   xhr.send(gzippedBlob);
1reaction
blacellecommented, Jan 24, 2018

Hello, I allow myself resurrecting this thread. Here is a Java snippet to handle pako String:

// Convert from pako String format to raw byte[]
byte[] asByteArray = new byte[html.length()];
for (int i = 0; i < html.length(); i++) {
	asByteArray[i] = (byte) html.charAt(i);
}
// Unzip the byte[]
try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(asByteArray));
		InputStreamReader osw = new InputStreamReader(gzipInputStream, StandardCharsets.UTF_8)) {
	html = CharStreams.toString(osw);
}

Pako provided the string with:

data.html = pako.gzip(data.html, { to: 'string' });
Read more comments on GitHub >

github_iconTop Results From Across the Web

JAVA not in gzip format error - Stack Overflow
4 Answers 4 · I found the gzip file on my computer and tried to gunzip it but it says "not in gzip...
Read more >
Dissecting the GZIP format - Command Line Fanatic
Dissecting the GZIP format. In this article I describe the DEFLATE algorithm that GZIP implements and depends on. The DEFLATE algorithm uses ...
Read more >
gzip — Support for gzip files — Python 3.11.1 documentation
Open a gzip-compressed file in binary or text mode, returning a file object. The filename argument can be an actual filename (a str...
Read more >
Tcl Reference Manual: zlib - TMML
Return the uncompressed contents of binary string string, which must have been in gzip format. If -headerVar is given, store a dictionary describing...
Read more >
Java GZIP Example - Compress and Decompress File
While decompressing a GZIP file, if it's not in GZIP format, following exception will be thrown. java.util.zip.ZipException: Not in GZIP format ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found