I've encountered what I believe is a valid GZIP file. However, attempting to read the contents results in the error gzip: invalid header. It's not clear to me what the error is, as the file is successfully decompressed with both gunzip and Java (see examples below).
import java.io.*;
import java.util.zip.GZIPInputStream;
public class Main {
public static void main(String[] args) {
var in = "C:\\Users\\Me\\Downloads\\Conifer_Desktop.spm";
var out = STR."\{in}.out";
decompressGzip(in, out);
}
public static void decompressGzip(String inputFile, String outputFile) {
try (var gis = new GZIPInputStream(new FileInputStream(inputFile));
var fos = new FileOutputStream(outputFile)) {
// copy GZIPInputStream to FileOutputStream
byte[] buffer = new byte[1024];
int len;
while ((len = gis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
I've encountered what I believe is a valid GZIP file. However, attempting to read the contents results in the error
gzip: invalid header
. It's not clear to me what the error is, as the file is successfully decompressed with bothgunzip
and Java (see examples below).Steps to Reproduce
Run the following reproducer code.
invalid header
Working Examples
gunzip
There is a warning about trailing garbage which may be relevant.
Java Code