lib/symmetric_encryption/reader.rb in symmetric-encryption-3.6.0 vs lib/symmetric_encryption/reader.rb in symmetric-encryption-3.7.0

- old
+ new

@@ -75,11 +75,11 @@ # csv.each {|row| p row} # ensure # csv.close if csv # end def self.open(filename_or_stream, options={}, &block) - raise "options must be a hash" unless options.respond_to?(:each_pair) + raise(ArgumentError, 'options must be a hash') unless options.respond_to?(:each_pair) mode = options.fetch(:mode, 'rb') compress = options.fetch(:compress, false) ios = filename_or_stream.is_a?(String) ? ::File.open(filename_or_stream, mode) : filename_or_stream begin @@ -113,11 +113,11 @@ @ios = ios @buffer_size = options.fetch(:buffer_size, 4096).to_i @version = options[:version] @header_present = false - raise "Buffer size cannot be smaller than 128" unless @buffer_size >= 128 + raise(ArgumentError, 'Buffer size cannot be smaller than 128') unless @buffer_size >= 128 read_header end # Returns whether the stream being read is compressed @@ -178,16 +178,18 @@ # remaining bytes def read(length=nil) data = nil if length return '' if length == 0 - return nil if @ios.eof? && (@read_buffer.length == 0) + return nil if eof? # Read length bytes while (@read_buffer.length < length) && !@ios.eof? read_block end - if @read_buffer.length > length + if @read_buffer.length == 0 + data = nil + elsif @read_buffer.length > length data = @read_buffer.slice!(0..length-1) else data = @read_buffer @read_buffer = '' end @@ -299,10 +301,10 @@ @read_buffer = '' end rewind offset = size + amount else - raise "unknown whence:#{whence} supplied to seek()" + raise(ArgumentError, "unknown whence:#{whence} supplied to seek()") end read(offset) if offset > 0 0 end