Class: DBF::Memo::Dbase4

Inherits:
Base
  • Object
show all
Defined in:
lib/dbf/memo/dbase4.rb

Constant Summary

Constants inherited from Base

Base::BLOCK_HEADER_SIZE, Base::BLOCK_SIZE

Instance Method Summary collapse

Methods inherited from Base

#close, #closed?, #get, #initialize, open

Constructor Details

This class inherits a constructor from DBF::Memo::Base

Instance Method Details

#build_memo(start_block) ⇒ Object

:nodoc:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dbf/memo/dbase4.rb', line 6

def build_memo(start_block) # :nodoc:
  data.seek offset(start_block)

  # A start block past EOF yields a nil/short header; return nil rather
  # than crashing on nil.unpack1.
  header = data.read(BLOCK_HEADER_SIZE)
  return nil unless header && header.bytesize == BLOCK_HEADER_SIZE

  length = header.unpack1('x4L')

  # Bound the read by the bytes remaining so a crafted 32-bit length
  # field cannot force a ~4 GiB allocation from a small memo file.
  remaining = data.size - data.pos
  length = remaining if length > remaining
  return nil if length <= 0

  data.read(length)
end