Xbase.DbtWriter (Xbase v0.1.0)
View SourceModule for writing and managing memo content in DBT files.
Provides comprehensive memo writing capabilities including append, update, deletion, block management, and file compaction. Coordinates with DBF record operations to maintain consistency.
Summary
Functions
Analyzes DBT file fragmentation and returns statistics.
Closes a DBT file opened for writing.
Compacts a DBT file by removing unused blocks and rebuilding the file.
Creates a new DBT file with initial header.
Marks a memo block as deleted by writing empty content.
Opens a DBT file for writing operations.
Updates existing memo content at a specific block.
Writes new memo content to the DBT file and returns the block number.
Functions
Analyzes DBT file fragmentation and returns statistics.
Parameters
dbt_file
- DbtFile structure
Returns
{:ok, %{total_blocks: n, used_blocks: n, free_blocks: n, fragmentation_ratio: f}}
{:error, reason}
- Error analyzing file
Closes a DBT file opened for writing.
Parameters
dbt_file
- DbtFile structure
Returns
:ok
- File closed successfully
Compacts a DBT file by removing unused blocks and rebuilding the file.
Parameters
dbt_file
- DbtFile structure to compactoutput_path
- Path for the compacted file (can be same as input)
Returns
{:ok, compacted_dbt_file}
- Successfully compacted DBT file{:error, reason}
- Error during compaction
Creates a new DBT file with initial header.
Parameters
file_path
- Path for the new DBT fileopts
- Options for DBT creation:version
- DBT format version (default: :dbase_iii):block_size
- Block size in bytes (default: 512)
Returns
{:ok, DbtFile.t()}
- Successfully created DBT file{:error, reason}
- Error creating file
Marks a memo block as deleted by writing empty content.
Parameters
dbt_file
- DbtFile structure opened for writingblock_number
- Block number to delete
Returns
{:ok, dbt_file}
- Successfully deleted memo{:error, reason}
- Error deleting memo
Opens a DBT file for writing operations.
Parameters
file_path
- Path to the DBT fileversion
- DBT format version (optional, defaults to :dbase_iii)
Returns
{:ok, DbtFile.t()}
- Successfully opened DBT file for writing{:error, reason}
- Error opening file
Updates existing memo content at a specific block.
Parameters
dbt_file
- DbtFile structure opened for writingblock_number
- Block number to updatecontent
- New memo content (string)
Returns
{:ok, dbt_file}
- Successfully updated memo{:error, reason}
- Error updating memo
Writes new memo content to the DBT file and returns the block number.
Parameters
dbt_file
- DbtFile structure opened for writingcontent
- Memo content to write (string)
Returns
{:ok, {block_number, updated_dbt_file}}
- Successfully written memo{:error, reason}
- Error writing memo