Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Zlib::Inflate#inflate

(::string string, ?buffer: ::String) -> ::String
(::string string, ?buffer: ::String) { (::String chunk) -> nil } -> nil
inflate(deflate_string, buffer: nil) → String
inflate(deflate_string, buffer: nil) { |chunk| ... } → nil

Inputs deflate_string into the inflate stream and returns the output from the stream. Calling this method, both the input and the output buffer of the stream are flushed. If string is nil, this method finishes the stream, just like Zlib::ZStream#finish.

If a block is given consecutive inflated chunks from the deflate_string are yielded to the block and nil is returned.

If a :buffer keyword argument is given and not nil:

  • The :buffer keyword should be a String, and will used as the output buffer. Using this option can reuse the memory required during inflation.

  • When not passing a block, the return value will be the same object as the :buffer keyword argument.

  • When passing a block, the yielded chunks will be the same value as the :buffer keyword argument.

Raises a Zlib::NeedDict exception if a preset dictionary is needed to decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then call this method again with an empty string to flush the stream:

Example
inflater = Zlib::Inflate.new

begin
  out = inflater.inflate compressed
rescue Zlib::NeedDict
  # ensure the dictionary matches the stream's required dictionary
  raise unless inflater.adler == Zlib.adler32(dictionary)

  inflater.set_dictionary dictionary
  inflater.inflate ''
end

# ...

inflater.close

See also Zlib::Inflate.new

See also .inflate #add_dictionary #set_dictionary #<< also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0