Method: Zlib::Inflate#initialize
- Defined in:
- ext/zlib/zlib.c
#initialize(*args) ⇒ Object
call-seq:
Zlib::Inflate.new(window_bits = Zlib::MAX_WBITS)
Creates a new inflate stream for decompression. window_bits
sets the size of the history buffer and can have the following values:
- 0
-
Have inflate use the window size from the zlib header of the compressed stream.
- (8..15)
-
Overrides the window size of the inflate header in the compressed stream. The window size must be greater than or equal to the window size of the compressed stream.
- Greater than 15
-
Add 32 to window_bits to enable zlib and gzip decoding with automatic header detection, or add 16 to decode only the gzip format (a Zlib::DataError will be raised for a non-gzip stream).
- (-8..-15)
-
Enables raw deflate mode which will not generate a check value, and will not look for any check values for comparison at the end of the stream.
This is for use with other formats that use the deflate compressed data format such as zip which provide their own check values.
Example
open "compressed.file" do |compressed_io|
zi = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
begin
open "uncompressed.file", "w+" do |uncompressed_io|
uncompressed_io << zi.inflate(compressed_io.read)
end
ensure
zi.close
end
end
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 |
# File 'ext/zlib/zlib.c', line 2042
static VALUE
rb_inflate_initialize(int argc, VALUE *argv, VALUE obj)
{
struct zstream *z;
VALUE wbits;
int err;
rb_scan_args(argc, argv, "01", &wbits);
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
err = inflateInit2(&z->stream, ARG_WBITS(wbits));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
ZSTREAM_READY(z);
return obj;
}
|