lib/zip/ioextras.rb in rubyzip-0.5.12 vs lib/zip/ioextras.rb in rubyzip-0.9.1
- old
+ new
@@ -31,29 +31,31 @@
end
attr_accessor :lineno
def read(numberOfBytes = nil, buf = nil)
- buf = "" unless (buf)
+ tbuf = nil
- if numberOfBytes
+ if @outputBuffer.length > 0
if numberOfBytes <= @outputBuffer.length
- buf[RANGE_ALL] = @outputBuffer.slice!(0, numberOfBytes)
+ tbuf = @outputBuffer.slice!(0, numberOfBytes)
else
- if @outputBuffer.length > 0
- buf[RANGE_ALL] = @outputBuffer + sysread(numberOfBytes - @outputBuffer.length, buf)
- @outputBuffer.slice!(RANGE_ALL)
- else
- buf[RANGE_ALL] = sysread(nil, buf)
- end
+ numberOfBytes -= @outputBuffer.length if (numberOfBytes)
+ rbuf = sysread(numberOfBytes, buf)
+ tbuf = @outputBuffer
+ tbuf << rbuf if (rbuf)
+ @outputBuffer = ""
end
else
- if @outputBuffer.length > 0
- buf[RANGE_ALL] = @outputBuffer + sysread(nil, buf)
- @outputBuffer.slice!(RANGE_ALL)
- else
- buf[RANGE_ALL] = sysread(nil, buf)
- end
+ tbuf = sysread(numberOfBytes, buf)
+ end
+
+ return nil unless (tbuf)
+
+ if buf
+ buf.replace(tbuf)
+ else
+ buf = tbuf
end
buf
end