Skip to content

Commit

Permalink
undo new_with_reader, use from_reader instead
Browse files Browse the repository at this point in the history
  • Loading branch information
digizeph committed Oct 16, 2024
1 parent 4b77766 commit 59f05f0
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,9 @@ impl Default for ParserOptions {
}
}

#[cfg(feature = "oneio")]
impl BgpkitParser<Box<dyn Read + Send>> {
/// Creating a new parser from an object that implements [Read] trait.
pub fn new_with_reader(reader: Box<dyn Read + Send>) -> Self {
BgpkitParser {
reader,
core_dump: false,
filters: vec![],
options: ParserOptions::default(),
}
}

/// Creating a new parser from a object that implements [Read] trait.
#[cfg(feature = "oneio")]
pub fn new(path: &str) -> Result<Self, ParserErrorWithBytes> {
let reader = get_reader(path)?;
Ok(BgpkitParser {
Expand All @@ -76,7 +66,6 @@ impl BgpkitParser<Box<dyn Read + Send>> {
/// The cache file name is generated by the following format: `cache-<crc32 of file name>-<file name>`.
/// For example, the remote file `http://archive.routeviews.org/route-views.chile/bgpdata/2023.03/RIBS/rib.20230326.0600.bz2`
/// will be cached as `cache-682cb1eb-rib.20230326.0600.bz2` in the cache directory.
#[cfg(feature = "oneio")]
pub fn new_cached(path: &str, cache_dir: &str) -> Result<Self, ParserErrorWithBytes> {
let file_name = path.rsplit('/').next().unwrap().to_string();
let new_file_name = format!(
Expand Down Expand Up @@ -108,7 +97,7 @@ fn add_suffix_to_filename(filename: &str, suffix: &str) -> String {
}

impl<R: Read> BgpkitParser<R> {
/// Creating a new parser from a object that implements [Read] trait.
/// Creating a new parser from an object that implements [Read] trait.
pub fn from_reader(reader: R) -> Self {
BgpkitParser {
reader,
Expand Down Expand Up @@ -167,14 +156,14 @@ mod tests {

#[test]
fn test_new_with_reader() {
// bzip2 reader for compressed file
// bzip2 reader for a compressed file
let reader = oneio::get_reader("http://archive.routeviews.org/route-views.ny/bgpdata/2023.02/UPDATES/updates.20230215.0630.bz2").unwrap();
assert_eq!(
12683,
BgpkitParser::from_reader(reader).into_elem_iter().count()
);

// remote reader for uncompressed updates file
// remote reader for an uncompressed updates file
let reader = oneio::get_reader("https://spaces.bgpkit.org/parser/update-example").unwrap();
assert_eq!(
8160,
Expand Down

0 comments on commit 59f05f0

Please sign in to comment.