lib/zip/ioextras.rb in bigtinker-0.97 vs lib/zip/ioextras.rb in bigtinker-0.98
- old
+ new
@@ -1,6 +1,18 @@
-module IOExtras
+module IOExtras #:nodoc:
+
+ CHUNK_SIZE = 32768
+
+ RANGE_ALL = 0..-1
+
+ def self.copy_stream(ostream, istream)
+ s = ''
+ ostream.write(istream.read(CHUNK_SIZE, s)) until istream.eof?
+ end
+
+
+ # Implements kind_of? in order to pretend to be an IO object
module FakeIO
def kind_of?(object)
object == IO || super
end
end
@@ -18,10 +30,38 @@
@outputBuffer = ""
end
attr_accessor :lineno
+ def read(numberOfBytes = nil, buf = nil)
+ tbuf = nil
+
+ if @outputBuffer.length > 0
+ if numberOfBytes <= @outputBuffer.length
+ tbuf = @outputBuffer.slice!(0, numberOfBytes)
+ else
+ numberOfBytes -= @outputBuffer.length if (numberOfBytes)
+ rbuf = sysread(numberOfBytes, buf)
+ tbuf = @outputBuffer
+ tbuf << rbuf if (rbuf)
+ @outputBuffer = ""
+ end
+ else
+ tbuf = sysread(numberOfBytes, buf)
+ end
+
+ return nil unless (tbuf)
+
+ if buf
+ buf.replace(tbuf)
+ else
+ buf = tbuf
+ end
+
+ buf
+ end
+
def readlines(aSepString = $/)
retVal = []
each_line(aSepString) { |line| retVal << line }
return retVal
end
@@ -64,10 +104,11 @@
alias_method :each, :each_line
end
- #relies on <<
+ # Implements many of the output convenience methods of IO.
+ # relies on <<
module AbstractOutputStream
include FakeIO
def write(data)
self << data