Fixed size buffer.
# File lib/buffer.rb, line 10 def self.from_string(str) new(str) end
# File lib/buffer.rb, line 61 def copy_from_stream(stream, n) raise ArgumentError if n < 0 while n > 0 str = stream.read(n) write(str) n -= str.size end raise if n < 0 end
# File lib/buffer.rb, line 33 def position=(new_pos) raise ArgumentError if new_pos < 0 or new_pos > @size @position = new_pos end
# File lib/buffer.rb, line 46 def read(n) raise EOF, 'cannot read beyond the end of buffer' if @position + n > @size str = @content[@position, n] @position += n str end
returns a Ruby string without the trailing NUL character
# File lib/buffer.rb, line 80 def read_cstring nul_pos = @content.index(NUL, @position) raise Error, "no cstring found!" unless nul_pos sz = nul_pos - @position str = @content[@position, sz] @position += sz + 1 return str end
read till the end of the buffer
# File lib/buffer.rb, line 91 def read_rest read(self.size-@position) end
Generated with the Darkfish Rdoc Generator 2.