GzipReader problem

S

StephenSykes

Shouldn't Zlib::GzipReader#read return "" when you try to read 0 bytes?
At the moment it returns nil, which differs in behaviour to IO#read.

This wouldn't normally matter, but Marshal sometimes tries to read 0
bytes during its work for some reason which I am trying to investigate
(anyone know what circumstances would cause marshal to do that?)
Regards,
Stephen
 
T

Tanaka Akira

StephenSykes said:
Shouldn't Zlib::GzipReader#read return "" when you try to read 0 bytes?
At the moment it returns nil, which differs in behaviour to IO#read.

I think it should be too.
This wouldn't normally matter, but Marshal sometimes tries to read 0
bytes during its work for some reason which I am trying to investigate
(anyone know what circumstances would cause marshal to do that?)
Regards,

Interesting example.

Index: ext/zlib/zlib.c
===================================================================
RCS file: /src/ruby/ext/zlib/zlib.c,v
retrieving revision 1.13
diff -u -p -r1.13 zlib.c
--- ext/zlib/zlib.c 23 Jun 2004 09:19:14 -0000 1.13
+++ ext/zlib/zlib.c 3 Aug 2004 16:13:48 -0000
@@ -2075,7 +2075,10 @@ gzfile_read(gz, len)
{
VALUE dst;

- if (len <= 0) return Qnil;
+ if (len < 0)
+ rb_raise(rb_eArgError, "negative length %ld given", len);
+ if (len == 0)
+ return rb_str_new(0, 0);
while (!ZSTREAM_IS_FINISHED(&gz->z) && gz->z.buf_filled < len) {
gzfile_read_more(gz);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top