Class: C0::StreamReader

Inherits:
Object
  • Object
show all
Defined in:
lib/c0.rb

Overview

An append-only log: committed region, torn-tail detection, blocks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf) ⇒ StreamReader

Returns a new instance of StreamReader.



220
221
222
223
# File 'lib/c0.rb', line 220

def initialize(buf)
  @buf = C0.to_bin(buf)
  @committed_end, @torn, @blocks = Ext.stream(@buf)
end

Instance Attribute Details

#committed_end ⇒ Object (readonly)

Returns the value of attribute committed_end.



218
219
220
# File 'lib/c0.rb', line 218

def committed_end
  @committed_end
end

Instance Method Details

#block(index) ⇒ Object



233
234
235
236
# File 'lib/c0.rb', line 233

def block(index)
  s, e = @blocks[index]
  @buf.byteslice(s, e - s)
end

#block_count ⇒ Object



231
# File 'lib/c0.rb', line 231

def block_count = @blocks.size

#blocks ⇒ Object



238
# File 'lib/c0.rb', line 238

def blocks = @blocks.map { |s, e| @buf.byteslice(s, e - s) }

#committed ⇒ Object



227
# File 'lib/c0.rb', line 227

def committed = @buf.byteslice(0, @committed_end)

#table ⇒ Object



240
# File 'lib/c0.rb', line 240

def table = Table.new(committed)

#tail ⇒ Object



229
# File 'lib/c0.rb', line 229

def tail = @buf.byteslice(@committed_end, @buf.bytesize - @committed_end)

#torn? ⇒ Boolean

Returns:

  • (Boolean)


225
# File 'lib/c0.rb', line 225

def torn? = @torn