lib/rio/ioh.rb in rio-0.3.7 vs lib/rio/ioh.rb in rio-0.3.8

- old
+ new

@@ -1,8 +1,8 @@ #-- # =============================================================================== -# Copyright (c) 2005, Christopher Kleckner +# Copyright (c) 2005, 2006 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify @@ -20,11 +20,11 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # =============================================================================== #++ # # To create the documentation for Rio run the command -# rake rdoc +# ruby build_doc.rb # from the distribution directory. Then point your browser at the 'doc/rdoc' directory. # # Suggested Reading # * RIO::Doc::SYNOPSIS # * RIO::Doc::INTRO @@ -56,13 +56,15 @@ def handle() @ios end def open?() not closed? end end class Stream < Base attr_reader :iostack + attr_accessor :hindex def initialize(iosp,*args) super @iostack = [@ios] + @hindex = -1 end def initialize_copy(*args) #p callstr('ioh_stream:initialize_copy',*args) super @iostack = @iostack.map { |io| io.nil? || io.equal?(@ios) ? io : io.clone } @@ -73,11 +75,11 @@ sz = nil if sz.nil? || sz == 0 end sz || 512 end - def handle() @iostack[-1] end + def handle() @iostack[@hindex] end def close() handle.close unless self.closed? end def closed?() handle.nil? or handle.closed? end def eof?() closed? or handle.eof? end def copy_stream(dst) #p callstr('copy_stream',dst) @@ -85,16 +87,25 @@ until handle.eof? dst.print(handle.read(blksize)) end self end - + def puts(*args) + handle.puts(*args) + end + def each_bytes(nb,&block) + until handle.eof? + break unless s = handle.read(nb) + yield s + end + self + end extend Forwardable def_instance_delegators(:handle,:binmode,:stat,:rewind, :each,:each_byte,:each_line,:gets,:getc, :read,:readlines,:readline,:sysread, - :<<,:print,:printf,:puts,:putc,:write,:syswrite, - :pos,:pos=,:lineno, + :<<,:print,:printf,:putc,:write,:syswrite, + :pos,:pos=,:lineno,:lineno=, :fileno, :close_read,:close_write, :fsync,:sync,:sync=,:fcntl,:ioctl) def method_missing(sym,*args,&block)