[macruby-changes] [1838] MacRuby/branches/experimental/io.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 11 12:11:27 PDT 2009


Revision: 1838
          http://trac.macosforge.org/projects/ruby/changeset/1838
Author:   pthomson at apple.com
Date:     2009-06-11 12:11:27 -0700 (Thu, 11 Jun 2009)
Log Message:
-----------
Implemented IO.copy_stream.

Modified Paths:
--------------
    MacRuby/branches/experimental/io.c

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-06-11 18:57:30 UTC (rev 1837)
+++ MacRuby/branches/experimental/io.c	2009-06-11 19:11:27 UTC (rev 1838)
@@ -3595,7 +3595,19 @@
 static VALUE
 rb_io_s_copy_stream(VALUE id, SEL sel, int argc, VALUE *argv)
 {
-    rb_notimplement();
+	VALUE src, dst, len, offset;
+	rb_scan_args(argc, argv, "22", &src, &dst, &len, &offset);
+	VALUE old_offset = rb_io_tell(src, 0); // save the old offset
+	if(!NIL_P(offset)) {
+		// seek if necessary
+		rb_io_seek(src, 0, offset);
+	}
+	VALUE data_read = (NIL_P(len) ? io_read(src, 0, 0, NULL) : io_read(src, 0, 1, &len));
+	VALUE copied = io_write(dst, 0, data_read);
+	if(!NIL_P(offset)) {
+		rb_io_seek(src, 0, old_offset); // restore the old offset
+	}
+	return copied;
 }
 
 /*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090611/83572b29/attachment-0001.html>


More information about the macruby-changes mailing list