File: foxpro.rb

package info (click to toggle)
ruby-dbf 4.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,732 kB
  • sloc: ruby: 1,692; makefile: 9
file content (32 lines) | stat: -rw-r--r-- 748 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module DBF
  module Memo
    class Foxpro < Base
      FPT_HEADER_SIZE = 512

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

        memo_type, memo_size, memo_string = @data.read(block_size).unpack('NNa*')
        return nil unless memo_type == 1 && memo_size > 0

        if memo_size > block_content_size
          memo_string << @data.read(content_size(memo_size))
        else
          memo_string = memo_string[0, memo_size]
        end
        memo_string
      rescue StandardError
        nil
      end

      private

      def block_size # :nodoc:
        @block_size ||= begin
          @data.rewind
          @data.read(FPT_HEADER_SIZE).unpack1('x6n') || 0
        end
      end
    end
  end
end