Xbase.DbtParser (Xbase v0.1.0)

View Source

Parser for DBT (memo) files used in dBase for storing variable-length text data.

DBT files store memo field content in a block-based structure with a 512-byte header followed by fixed-size blocks containing memo data terminated by 0x1A 0x1A markers.

Summary

Functions

Calculates the byte offset for a specific block number.

Closes a DBT file handle.

Extracts memo content from a block, handling termination markers.

Opens a DBT file and parses its header.

Parses a DBT file header from binary data.

Reads memo content from a specific block number.

Validates a DBT file for basic integrity.

Functions

calculate_block_offset(dbt_header, block_number)

Calculates the byte offset for a specific block number.

Parameters

  • header - DbtHeader structure
  • block_number - Block number to calculate offset for

Returns

  • Integer byte offset from start of file

close_dbt(dbt_file)

Closes a DBT file handle.

Parameters

  • dbt_file - DbtFile structure from open_dbt/1

Returns

  • :ok - File closed successfully

extract_memo_content(block_data)

Extracts memo content from a block, handling termination markers.

Parameters

  • block_data - Binary data from a memo block

Returns

  • {:ok, String.t()} - Extracted memo content
  • {:error, reason} - Error extracting content

open_dbt(file_path, version \\ :dbase_iii)

Opens a DBT file and parses its header.

Parameters

  • file_path - Path to the DBT file
  • version - DBT format version (optional)

Returns

  • {:ok, DbtFile.t()} - Successfully opened DBT file
  • {:error, reason} - Error opening or parsing file

parse_header(header_binary, version \\ :dbase_iii)

Parses a DBT file header from binary data.

Parameters

  • header_binary - 512 bytes of header data
  • version - DBT format version (defaults to :dbase_iii)

Returns

  • {:ok, DbtHeader.t()} - Successfully parsed header
  • {:error, reason} - Error parsing header

read_memo(dbt_file, block_number)

Reads memo content from a specific block number.

Parameters

  • dbt_file - DbtFile structure from open_dbt/1
  • block_number - Block number to read (1-based, 0 is header)

Returns

  • {:ok, String.t()} - Memo content
  • {:error, reason} - Error reading block

validate_dbt_file(file_path)

Validates a DBT file for basic integrity.

Parameters

  • file_path - Path to the DBT file to validate

Returns

  • {:ok, boolean()} - Validation result
  • {:error, reason} - Error during validation