Method: Zlib::Inflate#initialize
- Defined in:
- 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
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 |
# File 'zlib.c', line 1887 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; } |