I am having two application one written in java where required to zip string of data and other in golang and required to unzip the record zipped by first application
Java program to Creating Zipped of string data
public static byte[] createZipForLicenses(String string) throws UnsupportedEncodingException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
zipOutputStream.setLevel(Deflater.DEFAULT_COMPRESSION);
try {
if (string != null && string.length() > 0) {
ZipEntry zipEntry = new ZipEntry("data");
zipOutputStream.putNextEntry(zipEntry);
zipOutputStream.write(string.getBytes("UTF-8"));
zipOutputStream.closeEntry();
}
zipOutputStream.close();
} catch (IOException e) {
}
return outputStream.toByteArray();
}
Golang program to unzip the string data
func Unzip(data []byte) (string, error) {
rdata := bytes.NewReader(data)
r, err := zlib.NewReader(rdata) //**Error**-> "zlib: invalid header
if err != nil {
return "", err
}
s, err := io.ReadAll(r)
if err != nil {
return "", err
}
return string(s), nil
}
I tried using compress/flate lib also but with this getting error "flate: corrupt input before offset 5"