mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/zlib/zlib.c (Zlib::GzipFile#path): New method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5f956fda43
commit
2bb576e5ac
5 changed files with 73 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Apr 23 01:30:37 2009 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* ext/zlib/zlib.c (Zlib::GzipFile#path): New method.
|
||||
|
||||
Wed Apr 22 20:25:24 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* time.c (time_timespec): check out-of-range. [ruby-core:23282]
|
||||
|
|
4
NEWS
4
NEWS
|
@ -192,6 +192,10 @@ with all sufficient information, see the ChangeLog file.
|
|||
* Etc::Passwd.each
|
||||
* Etc::Group.each
|
||||
|
||||
* zlib
|
||||
* new methods:
|
||||
* Zlib::GzipFile#path
|
||||
|
||||
=== Compatibility issues (excluding feature bug fixes)
|
||||
|
||||
* Enumerator#rewind
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -363,6 +363,34 @@ if defined? Zlib
|
|||
assert_equal(3, gz.tell)
|
||||
end
|
||||
end
|
||||
|
||||
def test_path
|
||||
t = Tempfile.new("test_zlib_gzip_file")
|
||||
t.close
|
||||
|
||||
gz = Zlib::GzipWriter.open(t.path)
|
||||
gz.print("foo")
|
||||
assert_equal(t.path, gz.path)
|
||||
gz.close
|
||||
assert_equal(t.path, gz.path)
|
||||
|
||||
f = Zlib::GzipReader.open(t.path)
|
||||
assert_equal(t.path, f.path)
|
||||
f.close
|
||||
assert_equal(t.path, f.path)
|
||||
|
||||
s = ""
|
||||
sio = StringIO.new(s)
|
||||
gz = Zlib::GzipWriter.new(sio)
|
||||
gz.print("foo")
|
||||
assert_raise(NoMethodError) { gz.path }
|
||||
gz.close
|
||||
|
||||
sio = StringIO.new(s)
|
||||
f = Zlib::GzipReader.new(sio)
|
||||
assert_raise(NoMethodError) { f.path }
|
||||
f.close
|
||||
end
|
||||
end
|
||||
|
||||
class TestZlibGzipReader < Test::Unit::TestCase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue