Class: Zlib::Inflate
Instance Attribute Summary
Attributes inherited from ZStream
#buf, #flags, #func, #input, #stream
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ZStream
#ZSTREAM_IS_CLOSING, #ZSTREAM_IS_FINISHED, #ZSTREAM_IS_READY, #ZSTREAM_READY, #raise_zlib_error, #zstream_append_buffer, #zstream_append_input, #zstream_buffer_ungetc, #zstream_detach_buffer, #zstream_detach_input, #zstream_discard_input, #zstream_end, #zstream_expand_buffer, #zstream_init, #zstream_passthrough_input, #zstream_reset, #zstream_reset_input, #zstream_run, #zstream_shift_buffer, #zstream_sync
Constructor Details
#initialize(wbits = MAX_WBITS) ⇒ Inflate
Returns a new instance of Inflate.
41
42
43
44
45
46
47
48
49
|
# File 'lib/pr/zlib/inflate.rb', line 41
def initialize(wbits = MAX_WBITS)
@z = ZStream.new
@z.zstream_init(InflateFuncs)
err = inflateInit2(@z.stream, wbits)
if err != Z_OK
raise_zlib_error(err, @z.stream.msg)
end
@z.ZSTREAM_READY()
end
|
Class Method Details
.inflate(src) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/pr/zlib/inflate.rb', line 14
def self.inflate(src)
@z = ZStream.new
@z.zstream_init(InflateFuncs)
err = inflateInit(@z.stream)
if err != Z_OK
raise_zlib_error(err, @z.stream.msg)
end
@z.ZSTREAM_READY()
begin
dst = inflate_run(src)
ensure
@z.zstream_end
end
dst
end
|
.inflate_run(src) ⇒ Object
8
9
10
11
12
|
# File 'lib/pr/zlib/inflate.rb', line 8
def self.inflate_run(src)
@z.zstream_run(src, src.length, Z_SYNC_FLUSH)
@z.zstream_run('', 0, Z_FINISH)
@z.zstream_detach_buffer()
end
|
Instance Method Details
#<<(src) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/pr/zlib/inflate.rb', line 73
def <<(src)
if @z.ZSTREAM_IS_FINISHED()
if src
@z.zstream_append_buffer(src, src.length)
end
else
do_inflate(src)
if @z.ZSTREAM_IS_FINISHED()
@z.zstream_passthrough_input()
end
end
self
end
|
#inflate(src) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/pr/zlib/inflate.rb', line 51
def inflate(src)
if @z.ZSTREAM_IS_FINISHED()
if src.nil?
dst = @z.zstream_detach_buffer()
else
@z.zstream_append_buffer(src, src.lenth)
dst = ''
end
else
do_inflate(src)
dst = @z.zstream_detach_buffer()
if @z.ZSTREAM_IS_FINISHED()
@z.zstream_passthrough_input()
end
end
if block_given?
yield dst
else
dst
end
end
|
#set_dictionary(dic) ⇒ Object
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/pr/zlib/inflate.rb', line 103
def set_dictionary(dic)
src = dic
err = inflateSetDictionary(@z.stream, src, src.length)
if err != Z_OK
raise_zlib_error(err, @z.stream.msg)
end
dic
end
|
#sync ⇒ Object
87
88
89
90
|
# File 'lib/pr/zlib/inflate.rb', line 87
def sync
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@z.zstream_sync(src, src.length)
end
|
#sync_point? ⇒ Boolean
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/pr/zlib/inflate.rb', line 92
def sync_point?
err = inflateSyncPoint(@z.stream)
return true if err == 1
if err != Z_OK
raise_zlib_error(err, @z.stream.msg)
end
false
end
|