pub struct Reader<T: Read + Seek> { /* private fields */ }
Expand description
Struct with the handle to the source .dbf file Responsible for reading the content
Implementations§
Source§impl<T: Read + Seek> Reader<T>
impl<T: Read + Seek> Reader<T>
Sourcepub fn new(source: T) -> Result<Self, Error>
pub fn new(source: T) -> Result<Self, Error>
Creates a new reader from the source.
Reads the header and fields information as soon as its created.
Creating a reader from a file path using the from_path is the prefered way of doing it as it wraps the file in a BufReader for performance.
§Example
let mut reader = typed_shapefile::Reader::from_path("tests/data/line.dbf")?;
let records = reader.read()?;
use std::fs::File;
let f = File::open("tests/data/line.dbf").unwrap();
let reader = typed_shapefile::Reader::new(f)?;
Sourcepub fn new_with_encoding<E: Encoding + 'static>(
source: T,
encoding: E,
) -> Result<Self, Error>
pub fn new_with_encoding<E: Encoding + 'static>( source: T, encoding: E, ) -> Result<Self, Error>
Creates a new reader from the source and reads strings using the encoding provided.
See Self::new
for more information.
pub fn set_encoding<E: Encoding + 'static>(&mut self, encoding: E)
Sourcepub fn iter_records_as<R: ReadableRecord>(&mut self) -> RecordIterator<'_, T, R> ⓘ
pub fn iter_records_as<R: ReadableRecord>(&mut self) -> RecordIterator<'_, T, R> ⓘ
Creates an iterator of records of the type you want
Sourcepub fn iter_record_rows(&mut self) -> RecordRowIterator<'_, T>
pub fn iter_record_rows(&mut self) -> RecordRowIterator<'_, T>
Shortcut function to get an iterator over the Records in the file
Sourcepub fn iter_records(&mut self) -> RecordIterator<'_, T, Record> ⓘ
pub fn iter_records(&mut self) -> RecordIterator<'_, T, Record> ⓘ
Shortcut function to get an iterator over the Records in the file
Sourcepub fn read_as<R: ReadableRecord>(&mut self) -> Result<Vec<R>, Error>
pub fn read_as<R: ReadableRecord>(&mut self) -> Result<Vec<R>, Error>
Reads all the records of the file inside a Vec
Sourcepub fn seek(&mut self, index: usize) -> Result<(), Error>
pub fn seek(&mut self, index: usize) -> Result<(), Error>
Seek to the start of the record at index
Sourcepub fn into_table_info(self) -> TableInfo
pub fn into_table_info(self) -> TableInfo
Consumes the reader, and returns the info that allow to create a writer that would write a file with the same structure.
let mut reader = typed_shapefile::Reader::from_path("some_file.dbf")?;
let records = reader.read()?;
let table_info = reader.into_table_info();
let writer_1 = typed_shapefile::TableWriterBuilder::from_table_info(table_info.clone())
.build_with_file_dest("new_file_1.dbf");
let writer_2 = typed_shapefile::TableWriterBuilder::from_table_info(table_info)
.build_with_file_dest("new_file_2.dbf");