Parent

Class/Module Index [+]

Quicksearch

Redwood::MBox::Buffer

a simple buffer of contiguous data

Public Class Methods

new() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 21
def initialize
  clear!
end

Public Instance Methods

[](o) click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 54
def [](o)
  raise "only ranges supported due to programmer's laziness" unless o.is_a? Range
  @buf[Range.new(o.first - @start, o.last - @start, o.exclude_end?)]
end
add(data, offset=endd) click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 34
def add data, offset=endd
  #MBox::debug "+ adding #{data.length} bytes; size will be #{size + data.length}; limit #{SSHFile::MAX_BUF_SIZE}"

  if start.nil?
    @buf = data
    @start = offset
    return
  end

  raise "non-continguous data added to buffer (data #{offset}:#{offset + data.length}, buf range #{start}:#{endd})" if offset + data.length < start || offset > endd

  if offset < start
    @buf = data[0 ... (start - offset)] + @buf
    @start = offset
  else
    return if offset + data.length < endd
    @buf += data[(endd - offset) .. -1]
  end
end
clear!() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 25
def clear!
  @start = nil
  @buf = ""
end
empty?() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 30
def empty?; @start.nil?; end
endd() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 32
def endd; @start + @buf.length; end
index(what, start=0) click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 59
def index what, start=0
  x = @buf.index(what, start - @start)
  x.nil? ? nil : x + @start
end
rindex(what, start=0) click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 64
def rindex what, start=0
  x = @buf.rindex(what, start - @start)
  x.nil? ? nil : x + @start
end
size() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 69
def size; empty? ? 0 : @buf.size; end
start() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 31
def start; @start; end
to_s() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 70
def to_s; empty? ? "<empty>" : "[#{start}, #{endd})"; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.