class RBase::MemoFile::DBase3MemoFile
Constants
- BLOCK_SIZE
- BLOCK_TERMINATOR
- HEADER_SIZE
Public Class Methods
new(name)
click to toggle source
# File lib/rbase/memo_file.rb, line 19 def initialize(name) @file = File.open(name) @header = @file.read(HEADER_SIZE) @next_block = header.unpack('@0L') @version = header.unpack('@16c') end
Public Instance Methods
read(index)
click to toggle source
# File lib/rbase/memo_file.rb, line 27 def read(index) @file.pos = index*BLOCK_SIZE + HEADER_SIZE result = '' loop do data = @file.read(BLOCK_SIZE) terminator_pos = data.index(BLOCK_TERMINATOR) if terminator_pos break result + data[0, terminator_pos] end result += data end end
write(value)
click to toggle source
# File lib/rbase/memo_file.rb, line 41 def write(value) @file.pos = @next_block*BLOCK_SIZE + HEADER_SIZE value += BLOCK_TERMINATOR blocks_num = (value.length+511)/512 @file.write [value].pack("a#{512*blocks_num}") position = @next_block @next_block += blocks_num update_header position end
Protected Instance Methods
update_header()
click to toggle source
# File lib/rbase/memo_file.rb, line 56 def update_header @file.pos = 0 @file.write [@next_block].pack("L") end