Project

General

Profile

Actions

Bug #6273

closed

confusing rdoc on Zlib

Added by lparra (Luis Parravicini) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
trunk
Backport:
[ruby-core:44200]

Description

=begin
The rdoc at ext/zlib/zlib.c gives some examples of code to deflate/inflate a string. If you try to use them to actually deflate/inflate it gives an error inflating.

The deflate snippet is:

def deflate(string, level)
z = Zlib::Deflate.new(level)
dst = z.deflate(string, Zlib::NO_FLUSH)
z.close
dst
end

And the inflate snippet is:

def inflate(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
buf
end

And then testing them with:

inflate(deflate("test-string", 6))

It returns "Zlib::BufError: buffer error".

The error is because the flush parameter used is NO_FLUSH. It should be changed to FINISH for the deflating/inflating to work.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0