[macruby-changes] [4558] MacRuby/trunk/ext/zlib/zlib.c
source_changes at macosforge.org
source_changes at macosforge.org
Wed Sep 29 07:14:54 PDT 2010
Revision: 4558
http://trac.macosforge.org/projects/ruby/changeset/4558
Author: watson1978 at gmail.com
Date: 2010-09-29 07:14:51 -0700 (Wed, 29 Sep 2010)
Log Message:
-----------
Fixed the Zlib::GzipReader#getbyte, #readbyte and #each_char.
Modified Paths:
--------------
MacRuby/trunk/ext/zlib/zlib.c
Modified: MacRuby/trunk/ext/zlib/zlib.c
===================================================================
--- MacRuby/trunk/ext/zlib/zlib.c 2010-09-29 01:14:30 UTC (rev 4557)
+++ MacRuby/trunk/ext/zlib/zlib.c 2010-09-29 14:14:51 UTC (rev 4558)
@@ -2888,14 +2888,59 @@
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
+rb_gzreader_getbyte(VALUE obj, SEL sel)
+{
+ struct gzfile *gz = get_gzfile(obj);
+ VALUE dst;
+
+ dst = gzfile_read(gz, 1);
+ if (!NIL_P(dst)) {
+ dst = INT2FIX((unsigned int)(BSTRING_PTR(dst)[0]) & 0xff);
+ }
+ return dst;
+}
+
+/*
+ * See Zlib::GzipReader documentation for a description.
+ */
+static VALUE
+rb_gzreader_readbyte(VALUE obj, SEL sel)
+{
+ VALUE dst;
+ dst = rb_gzreader_getbyte(obj, 0);
+ if (NIL_P(dst)) {
+ rb_raise(rb_eEOFError, "end of file reached");
+ }
+ return dst;
+}
+
+/*
+ * See Zlib::GzipReader documentation for a description.
+ */
+static VALUE
+rb_gzreader_each_char(VALUE obj, SEL sel)
+{
+ VALUE c;
+
+ RETURN_ENUMERATOR(obj, 0, 0);
+
+ while (!NIL_P(c = rb_gzreader_getc(obj, 0))) {
+ rb_yield(c);
+ }
+ return Qnil;
+}
+
+/*
+ * See Zlib::GzipReader documentation for a description.
+ */
+static VALUE
rb_gzreader_each_byte(VALUE obj, SEL sel)
{
VALUE c;
RETURN_ENUMERATOR(obj, 0, 0);
- while (!NIL_P(c = rb_gzreader_getc(obj, 0))) {
- c = INT2FIX((unsigned int)(BSTRING_PTR(c)[0]) & 0xff);
+ while (!NIL_P(c = rb_gzreader_getbyte(obj, 0))) {
rb_yield(c);
}
return Qnil;
@@ -3323,8 +3368,11 @@
rb_objc_define_method(cGzipReader, "read", rb_gzreader_read, -1);
rb_objc_define_method(cGzipReader, "readpartial", rb_gzreader_readpartial, -1);
rb_objc_define_method(cGzipReader, "getc", rb_gzreader_getc, 0);
+ rb_objc_define_method(cGzipReader, "getbyte", rb_gzreader_getbyte, 0);
rb_objc_define_method(cGzipReader, "readchar", rb_gzreader_readchar, 0);
+ rb_objc_define_method(cGzipReader, "readbyte", rb_gzreader_readbyte, 0);
rb_objc_define_method(cGzipReader, "each_byte", rb_gzreader_each_byte, 0);
+ rb_objc_define_method(cGzipReader, "each_char", rb_gzreader_each_char, 0);
rb_objc_define_method(cGzipReader, "bytes", rb_gzreader_each_byte, 0);
rb_objc_define_method(cGzipReader, "ungetc", rb_gzreader_ungetc, 1);
rb_objc_define_method(cGzipReader, "gets", rb_gzreader_gets, -1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100929/6f98b0d4/attachment.html>
More information about the macruby-changes
mailing list