Class: Rubcask::HintFile
- Inherits:
-
Object
- Object
- Rubcask::HintFile
- Extended by:
- Forwardable
- Defined in:
- lib/rubcask/hint_file.rb
Overview
HintFile stores only keys, and information on where the value of the key is located
Constant Summary collapse
- HEADER_FORMAT =
"Q>nNQ>"
Instance Method Summary collapse
-
#append(entry) ⇒ Integer
Appends an entry to the file.
-
#each {|hint_entry| ... } ⇒ Enumerator
Yields each hint entry from the file.
-
#initialize(file) ⇒ HintFile
constructor
A new instance of HintFile.
-
#read ⇒ HintEntry?
Reads hint entry at the current offset.
Constructor Details
#initialize(file) ⇒ HintFile
Returns a new instance of HintFile.
12 13 14 |
# File 'lib/rubcask/hint_file.rb', line 12 def initialize(file) @file = file end |
Instance Method Details
#append(entry) ⇒ Integer
Appends an entry to the file
49 50 51 52 53 54 |
# File 'lib/rubcask/hint_file.rb', line 49 def append(entry) @file.write( [entry., entry.key.bytesize, entry.value_size, entry.value_pos].pack(HEADER_FORMAT), entry.key ) end |
#each {|hint_entry| ... } ⇒ Enumerator
Yields each hint entry from the file
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubcask/hint_file.rb', line 19 def each return to_enum(__method__) unless block_given? seek(0) loop do val = read break unless val yield val end end |
#read ⇒ HintEntry?
Reads hint entry at the current offset
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubcask/hint_file.rb', line 35 def read header = @file.read(22) return nil unless header , key_size, value_size, value_pos = header.unpack(HEADER_FORMAT) key = @file.read(key_size) HintEntry.new(, key, value_pos, value_size) end |