lib/rio/ioh.rb in rio-0.4.2 vs lib/rio/ioh.rb in rio-0.5.1
- old
+ new
@@ -1,8 +1,8 @@
#--
-# ===============================================================================
-# Copyright (c) 2005,2006,2007,2008 Christopher Kleckner
+# ===========================================================================
+# Copyright (c) 2005-2012 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
@@ -16,32 +16,21 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rio; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-# ===============================================================================
+# ===========================================================================
#++
#
-# To create the documentation for Rio run the command
-# ruby build_doc.rb
-# from the distribution directory.
-#
-# Suggested Reading
-# * RIO::Doc::SYNOPSIS
-# * RIO::Doc::INTRO
-# * RIO::Doc::HOWTO
-# * RIO::Doc::EXAMPLES
-# * RIO::Rio
-#
#require 'fileutils'
module RIO
module IOH #:nodoc: all
class Base
- attr :ios
+ attr_accessor :ios
def initialize(ios,*args)
@ios = ios
end
def initialize_copy(other)
#p callstr('ioh:initialize_copy',other)
@@ -50,38 +39,41 @@
@ios = other.ios.clone unless other.ios.nil?
end
def callstr(func,*args)
self.class.to_s+'['+self.to_s+']'+'.'+func.to_s+'('+args.join(',')+')'
end
- def handle() @ios end
- def open?() not closed? end
+ def ior() ios end
+ def iow() ios end
+ def handle() ios end
+ def open?() not closed? end
end
+
+
+
+
class Stream < Base
- attr_reader :iostack
+ #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 }
end
def copy_blksize()
- if @ios.respond_to? :stat
- sz = @ios.stat.blksize
+ if ios.respond_to? :stat
+ sz = ios.stat.blksize
sz = nil if sz.nil? || sz == 0
end
sz || 512
end
- def handle() @iostack[@hindex] end
+ def handle() ios 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 closed?() ios.nil? or ios.closed? end
+ def eof?() ios.nil? or ios.closed? or ios.eof? end
def copy_stream(dst)
#p callstr('copy_stream',dst)
blksize = _stream_blksize(handle,dst)
until handle.eof?
dst.print(handle.read(blksize))
@@ -96,22 +88,23 @@
break unless s = handle.read(nb)
yield s
end
self
end
- def each_line(*args,&block)
- handle.each_line(*args,&block)
- end
extend Forwardable
def_instance_delegators(:handle,:binmode,:stat,:rewind,
:each,:each_byte,:gets,:getc,
+ :each_line,
:read,:readlines,:readline,:sysread,
:<<,:print,:printf,:putc,:write,:syswrite,
:pos,:pos=,:lineno,:lineno=,
:fileno,
:close_read,:close_write,
:fsync,:sync,:sync=,:fcntl,:ioctl)
+ def set_encoding(*args)
+ handle.set_encoding(*args)
+ end
def method_missing(sym,*args,&block)
#p callstr('method_missing',sym,*args)
handle.__send__(sym,*args,&block)
end
@@ -131,20 +124,28 @@
return nil unless s
return nil if s == 0
s
end
end
+
+
+
+
+
class Dir < Base
def close
- #p "#{callstr('close')} ios=#{@ios}"
- unless @ios.nil?
- @ios.close
- @ios = nil
+ #p "#{callstr('close')} ios=#{ios}"
+ unless ios.nil?
+ ios.close
+ ios = nil
end
end
- def closed?() @ios.nil? end
+ def closed?() ios.nil? end
def each(&block)
+ #p handle
while filename = handle.read
+ #p "IOH: #{filename.inspect} FS_ENCODING=#{FS_ENCODING}"
+ #yield filename.force_encoding(FS_ENCODING)
yield filename
end
end
def each0(&block)
handle.each { |filename|