summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-04-22 16:31:06 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-04-22 16:31:06 +0000
commit3192a485d25f48e5c7492c953f181b7a373e4eaa (patch)
treea6b370f42b1e910d78c50a0035eb1909f08ef93a /ext
parent3909c0237c013a21e29a3e27d1c94c3520d262f6 (diff)
downloadruby-3192a485d25f48e5c7492c953f181b7a373e4eaa.tar.gz
ruby-3192a485d25f48e5c7492c953f181b7a373e4eaa.tar.xz
ruby-3192a485d25f48e5c7492c953f181b7a373e4eaa.zip
* ext/zlib/zlib.c (Zlib::GzipFile#path): New method.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/zlib/doc/zlib.rd6
-rw-r--r--ext/zlib/zlib.c32
2 files changed, 37 insertions, 1 deletions
diff --git a/ext/zlib/doc/zlib.rd b/ext/zlib/doc/zlib.rd
index 6a36dc7fe..0a5e2d0ab 100644
--- a/ext/zlib/doc/zlib.rd
+++ b/ext/zlib/doc/zlib.rd
@@ -543,6 +543,12 @@ GzipReader should be used with associating an instance of IO class
must respond to flush method. While `sync' mode is true,
the compression ratio decreases sharply.
+--- Zlib::GzipFile#path
+
+ Returns the path string of the associated IO-like object. This
+ method is only defined when the IO-like object responds to
+ #path().
+
== Zlib::GzipFile::Error
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index c7ca55cc1..288b13b72 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -163,6 +163,7 @@ static VALUE rb_gzfile_sync(VALUE);
static VALUE rb_gzfile_set_sync(VALUE, VALUE);
static VALUE rb_gzfile_total_in(VALUE);
static VALUE rb_gzfile_total_out(VALUE);
+static VALUE rb_gzfile_path(VALUE);
static VALUE rb_gzwriter_s_allocate(VALUE);
static VALUE rb_gzwriter_s_open(int, VALUE*, VALUE);
@@ -1653,7 +1654,7 @@ rb_inflate_set_dictionary(VALUE obj, VALUE dic)
#define OS_CODE OS_UNIX
#endif
-static ID id_write, id_read, id_readpartial, id_flush, id_seek, id_close;
+static ID id_write, id_read, id_readpartial, id_flush, id_seek, id_close, id_path;
static VALUE cGzError, cNoFooter, cCRCError, cLengthError;
@@ -1678,6 +1679,7 @@ struct gzfile {
int ecflags;
VALUE ecopts;
char *cbuf;
+ VALUE path;
};
#define GZFILE_CBUF_CAPA 10
@@ -1699,6 +1701,7 @@ gzfile_mark(struct gzfile *gz)
rb_gc_mark(gz->comment);
zstream_mark(&gz->z);
rb_gc_mark(gz->ecopts);
+ rb_gc_mark(gz->path);
}
static void
@@ -1745,6 +1748,7 @@ gzfile_new(klass, funcs, endfunc)
gz->ecflags = 0;
gz->ecopts = Qnil;
gz->cbuf = 0;
+ gz->path = Qnil;
return obj;
}
@@ -2673,6 +2677,21 @@ rb_gzfile_total_out(VALUE obj)
return rb_uint2inum(gz->z.stream.total_out - gz->z.buf_filled);
}
+/*
+ * Document-method: path
+ *
+ * call-seq: path
+ *
+ * Returns the path string of the associated IO-like object. This
+ * method is only defined when the IO-like object responds to #path().
+ */
+static VALUE
+rb_gzfile_path(VALUE obj)
+{
+ struct gzfile *gz;
+ Data_Get_Struct(obj, struct gzfile, gz);
+ return gz->path;
+}
static void
rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
@@ -2770,6 +2789,11 @@ rb_gzwriter_initialize(int argc, VALUE *argv, VALUE obj)
ZSTREAM_READY(&gz->z);
rb_gzfile_ecopts(gz, opt);
+ if (rb_respond_to(io, id_path)) {
+ gz->path = rb_funcall(gz->io, id_path, 0);
+ rb_define_singleton_method(obj, "path", rb_gzfile_path, 0);
+ }
+
return obj;
}
@@ -2965,6 +2989,11 @@ rb_gzreader_initialize(int argc, VALUE *argv, VALUE obj)
gzfile_read_header(gz);
rb_gzfile_ecopts(gz, opt);
+ if (rb_respond_to(io, id_path)) {
+ gz->path = rb_funcall(gz->io, id_path, 0);
+ rb_define_singleton_method(obj, "path", rb_gzfile_path, 0);
+ }
+
return obj;
}
@@ -3516,6 +3545,7 @@ Init_zlib()
id_flush = rb_intern("flush");
id_seek = rb_intern("seek");
id_close = rb_intern("close");
+ id_path = rb_intern("path");
cGzipFile = rb_define_class_under(mZlib, "GzipFile", rb_cObject);
cGzError = rb_define_class_under(cGzipFile, "Error", cZError);