Sha256: 9ad72e31dd7ae071bdf28f41ba256881ccf44de2bb1329d6ce13e14474eebf91

Contents?: true

Size: 909 Bytes

Versions: 2

Compression:

Stored size: 909 Bytes

Contents

module DBF
  module Memo
    class Base
      BLOCK_HEADER_SIZE = 8
      BLOCK_SIZE = 512

      def self.open(filename, version)
        new(File.open(filename, 'rb'), version)
      end

      def initialize(data, version)
        @data = data
        @version = version
      end

      def get(start_block)
        return nil unless start_block > 0
        build_memo start_block
      end

      def close
        @data.close && @data.closed?
      end

      def closed?
        @data.closed?
      end

      private

      def offset(start_block) # :nodoc:
        start_block * block_size
      end

      def content_size(memo_size) # :nodoc:
        (memo_size - block_size) + BLOCK_HEADER_SIZE
      end

      def block_content_size # :nodoc:
        @block_content_size ||= block_size - BLOCK_HEADER_SIZE
      end

      def block_size # :nodoc:
        BLOCK_SIZE
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dbf-3.1.3 lib/dbf/memo/base.rb
dbf-3.1.2 lib/dbf/memo/base.rb