lib/rio/stream.rb in rio-0.4.2 vs lib/rio/stream.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,38 +16,34 @@ # 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 'rio/stream/base' +module RIO + autoload :Ops, 'rio/ops' + module Stream + autoload :Open, 'rio/stream/open' + autoload :Duplex, 'rio/stream/duplex' + end +end +require 'rio/filter' require 'rio/ops/path' require 'rio/ops/stream' require 'rio/ops/stream/input' require 'rio/ops/stream/output' require 'rio/ext' - require 'rio/filter/gzip' #require 'rio/filter/yaml' #require 'rio/filter/chomp' #require 'rio/filter/strip' -require 'rio/filter/closeoneof' +#require 'rio/filter/closeoneof' module RIO module Stream #:nodoc: all class Reset < Base @@ -58,14 +54,17 @@ def check?() true end def when_missing(sym,*args) retryreset() end end class IOBase < Base + + # Mixin the appropriate ops include Ops::Path::Str include Ops::Stream::Status include Ops::Stream::Manip + def check?() open? end def when_missing(sym,*args) #p callstr('when_missing',sym,*args) retryreset() @@ -74,10 +73,12 @@ def reset() self.close.softreset() end def setup ioh.sync = sync? if cx.has_key?('sync') + + ioh.set_encoding(*enc?) if cx.has_key?(:enc_args) self end def add_filter(mod) unless ioh.kind_of?(mod) ioh.extend(mod) @@ -100,10 +101,11 @@ module Ini def setup super @recno = -1 @get_selrej,@get_rangetops = create_selrej() + # @cursor = io_enum self end end class Input < IOBase include Ops::Stream::Input @@ -115,12 +117,25 @@ #p callstr('add_extensions') Ext::Input.add_extensions(self) end def add_filters #p "IN stream#add_filters" - add_filter(Filter::GZipRead) if gzip? - #add_filter(Filter::YAML) if yaml? + if gzip? + gz = Zlib::GzipReader.new(self.ioh.ios) + gz.extend Filter::GZipMissing + gz.extend Filter::GZipWin32MissingEachLine + self.ioh.ios = gz + add_filter(Filter::GZipRead) + end + if csv? + require 'rio/ext/csv/filter' if $USE_FASTER_CSV + self.extend(::RIO::Ext::CSV::Input) + add_csv_filter() if $USE_FASTER_CSV +# csvio = CSV.new(self.ioh.ios,*cx['csv_args']) +# self.ioh.ios = csvio + end + #add_filter(Filter::YAML) if yaml? add_line_filters() # add_filter(Filter::FasterCSV) if csv? # if closeoneof? # add_filter(Filter::CloseOnEOF) # ioh.oncloseproc = proc { self.on_closeoneof } @@ -140,10 +155,22 @@ end def add_extensions() Ext::Output.add_extensions(self) end def add_filters - add_filter(Filter::GZipWrite) if gzip? + if gzip? + gz = Zlib::GzipWriter.new(self.ioh.ios) + gz.extend Filter::GZipMissing + self.ioh.ios = gz + add_filter(Filter::GZipWrite) + end + if csv? + require 'rio/ext/csv/filter' if $USE_FASTER_CSV + self.extend(::RIO::Ext::CSV::Output) + add_csv_filter() if $USE_FASTER_CSV +# csvio = CSV.new(self.ioh.ios,*cx['csv_args']) +# self.ioh.ios = csvio + end #add_filter(Filter::FasterCSV) if csv? #add_filter(Filter::YAML) if yaml? self end