Skip to main content

Crate datasus_core

Crate datasus_core 

Source
Expand description

Reader for DATASUS .dbc files (and plain .dbf).

A DBC file is a dBase III header followed by the record area compressed with the PKWare Data Compression Library. This crate decompresses it (blast), recognises the container layout (decode) and parses the records into typed columns (Table).

It is a port of the C reader of the datasusr R package and is meant to produce the same values for the same options. It has no dependencies so it can be embedded anywhere (R packages, Python wheels, CLIs).

use datasus_core::{open, ReadOptions};

let table = open("RDPE2401.dbc", &ReadOptions::default())?;
println!("{} rows x {} columns", table.n_rows(), table.n_cols());
let columns = table.collect();

Modules§

blast
Decompressor for PKWare Data Compression Library (DCL “implode”) streams.

Structs§

Cursor
Position inside the record area, so rows can be read in batches.
DbfData
An uncompressed DBF: header bytes and record area.
Field
A field as declared in the DBF header.
ReadOptions
Reader options; the defaults match read_datasus_dbc().
Table
A parsed DBF header plus the record area it describes.

Enums§

ColType
Output type of a column.
ColumnData
A decoded column, for callers that just want the data in memory.
Container
How the input was recognised.
Encoding
Encoding of character fields.
Error

Constants§

DEFAULT_MAX_DECOMPRESSED
Default bound on decompressed size used by decode: 4 GiB, twice the largest file dBase itself can address.

Traits§

Sink
Receives decoded values, one call per selected column per row, in row order. col indexes Table::columns; row restarts at 0 on every Table::read_rows call.

Functions§

decode
Recognise the layout of buf and decompress the record area if needed.
decode_with_limit
Same as decode, failing with Error::TooLarge if the file would decompress to more than max_bytes. Lower it when reading untrusted files: a PKWare DCL stream can expand to hundreds of times its size.
from_bytes
Same as open, for a file already in memory.
open
Read and decode a .dbc/.dbf file and plan how to read it.
repair_names
Make column names unique the way tibble’s "unique" repair does: empty and duplicated names get a ...<position> suffix. With clean, names are lowercased afterwards (datasusr’s clean_names).