XRBSourceXRBIOBuffer

class IOBuffer

Represents an IO buffer with a given path.

Definitions

def initialize(io, path: io.inspect)

Create a new IO buffer from an IO object.

Signature

parameter io IO

the IO object to use as the buffer.

parameter path String

the path to use for the buffer.

Implementation

def initialize(io, path: io.inspect)
	@io = io
	@path = path
	@cache = nil
end

def freeze

Freeze the buffer, caching the contents of the IO object.

Implementation

def freeze
	return self if frozen?
	
	read
	
	super
end

attr :path

Signature

attribute String

the path name of the buffer.

def encoding

Signature

returns Encoding

the encoding of the buffer.

Implementation

def encoding
	read.encoding
end

def read

Read the contents of the IO object into the buffer.

Implementation

def read
	unless @cache
		@cache = @io.read.freeze
		@io.close
	end
	
	return @cache
end

def to_buffer

Signature

returns Buffer

a buffer with the contents of the IO object.

Implementation

def to_buffer
	Buffer.new(self.read, path: @path)
end