Skip to content

Commit e3edae7

Browse files
committed
support decompressing streams without zlib header in Java code of zlib module
1 parent 39754d4 commit e3edae7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/zlib/ZLibModuleBuiltins.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -601,9 +601,12 @@ Object error(VirtualFrame frame, Object data, Object wbits, Object bufsize) {
601601
}
602602

603603
@TruffleBoundary
604-
byte[] javaDecompress(byte[] array, @SuppressWarnings("unused") int wbits, int bufsize) throws DataFormatException {
605-
// We don't use wbits currently. There is no easy way how to map to java Inflater.
606-
Inflater decompresser = new Inflater();
604+
byte[] javaDecompress(byte[] array, int wbits, int bufsize) throws DataFormatException {
605+
// zlib can decompress all those formats:
606+
// to (de-)compress deflate format, use wbits = -zlib.MAX_WBITS
607+
// to (de-)compress zlib format, use wbits = zlib.MAX_WBITS
608+
// to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16
609+
Inflater decompresser = new Inflater(wbits < 0 || (wbits & 16) == 16);
607610
decompresser.setInput(array);
608611
byte[] resultArray = new byte[bufsize];
609612
ByteArrayOutputStream baos = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)