module IOExtensions
IOExtensions
provides convenience wrappers for certain IO functionality.
Public Class Methods
read_exactly(io, length, buffer = '')
click to toggle source
Reads and returns exactly length bytes from io using the read method on io. If there is insufficient data available, an EOFError is raised.
# File lib/archive/support/ioextensions.rb, line 7 def self.read_exactly(io, length, buffer = '') buffer.slice!(0..-1) unless buffer.empty? while buffer.size < length do internal = io.read(length - buffer.size) raise EOFError, 'unexpected end of file' if internal.nil? buffer << internal end buffer end