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.
- Read
Options - 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.
- Column
Data - 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.
colindexesTable::columns;rowrestarts at 0 on everyTable::read_rowscall.
Functions§
- decode
- Recognise the layout of
bufand decompress the record area if needed. - decode_
with_ limit - Same as
decode, failing withError::TooLargeif the file would decompress to more thanmax_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/.dbffile 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. Withclean, names are lowercased afterwards (datasusr’sclean_names).