Xbase.CdxParser (Xbase v0.1.0)

View Source

Parser for CDX (compound index) files used in dBase for fast data access.

CDX files implement a B-tree structure with 512-byte pages containing root, branch, and leaf nodes. The file begins with a header containing metadata about the index structure and key expressions.

Summary

Functions

Closes a CDX file handle and cleans up resources.

Opens a CDX file and parses its header.

Parses a CDX file header from binary data.

Parses a CDX B-tree node from binary page data.

Reads a B-tree node from a specific page number.

Searches for a key in the B-tree starting from the root node.

Functions

close_cdx(cdx_file)

Closes a CDX file handle and cleans up resources.

Parameters

  • cdx_file - CdxFile structure from open_cdx/1

Returns

  • :ok - File closed successfully

open_cdx(file_path)

Opens a CDX file and parses its header.

Parameters

  • file_path - Path to the CDX file

Returns

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

parse_header(header_binary)

Parses a CDX file header from binary data.

Parameters

  • header_binary - 512 bytes of header data

Returns

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

parse_node(page_data, key_length \\ 10)

Parses a CDX B-tree node from binary page data.

Parameters

  • page_data - 512 bytes of page data
  • key_length - Length of keys in this index

Returns

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

read_node(cdx_file, page_number)

Reads a B-tree node from a specific page number.

Parameters

  • cdx_file - CdxFile structure from open_cdx/1
  • page_number - Page number to read (0-based)

Returns

  • {:ok, CdxNode.t()} - Successfully read node
  • {:error, reason} - Error reading node

search_key(cdx_file, search_key)

Searches for a key in the B-tree starting from the root node.

Parameters

  • cdx_file - CdxFile structure
  • search_key - Key to search for

Returns

  • {:ok, record_number} - Found key, returns record number
  • {:error, :not_found} - Key not found
  • {:error, reason} - Error during search