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
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 |
# File 'zlib.c', line 1867
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);
Data_Get_Struct(obj, struct zstream, z);
err = inflateInit2(&z->stream, ARG_WBITS(wbits));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
ZSTREAM_READY(z);
return obj;
}
|