From bb4d9daf85e21385ef92e4e08514a599d9a6df4a Mon Sep 17 00:00:00 2001 From: arya dradjica Date: Thu, 24 Jul 2025 22:40:14 +0200 Subject: [PATCH] [examples/read-zone] Use 'new::zonefile' --- Cargo.toml | 2 +- examples/read-zone.rs | 48 +++++++++---------------------------------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6bcfcbb9..d165a077 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -170,7 +170,7 @@ required-features = ["net", "tokio-stream", "tracing-subscriber", "unstable-clie [[example]] name = "read-zone" -required-features = ["zonefile"] +required-features = ["zonefile", "unstable-new"] [[example]] name = "query-zone" diff --git a/examples/read-zone.rs b/examples/read-zone.rs index 39029915..aa87ec6d 100644 --- a/examples/read-zone.rs +++ b/examples/read-zone.rs @@ -1,12 +1,11 @@ //! Reads a zone file. -use std::env; use std::fs::File; use std::process::exit; use std::time::SystemTime; +use std::{env, io::BufReader}; -use domain::zonefile::inplace::Entry; -use domain::zonefile::inplace::Zonefile; +use domain::new::zonefile::simple::ZonefileScanner; fn main() { let mut args = env::args(); @@ -23,44 +22,17 @@ fn main() { for zone_file in zone_files { print!("Processing {zone_file}: "); let start = SystemTime::now(); - let mut reader = - Zonefile::load(&mut File::open(&zone_file).unwrap()).unwrap(); - println!( - "Data loaded ({:.03}s).", - start.elapsed().unwrap().as_secs_f32() - ); + let file = BufReader::new(File::open(&zone_file).unwrap()); + let mut scanner = ZonefileScanner::new(file, None); let mut i = 0; - let mut last_entry = None; - loop { - match reader.next_entry() { - Ok(entry) if entry.is_some() => { - last_entry = entry; - } - Ok(_) => break, // EOF - Err(err) => { - eprintln!( - "\nAn error occurred while reading {zone_file}:" - ); - eprintln!(" Error: {err}"); - if let Some(entry) = &last_entry { - if let Entry::Record(record) = &entry { - eprintln!( - "\nThe last record read was:\n{record}." - ); - } else { - eprintln!( - "\nThe last record read was:\n{last_entry:#?}." - ); - } - eprintln!( - "\nTry commenting out the line after that record with a leading ; (semi-colon) character." - ) - } - exit(1); - } - } + while let Some(entry) = scanner.scan().transpose() { i += 1; + if let Err(err) = entry { + eprintln!("Could not parse {zone_file}: {err}"); + exit(1); + } + if i % 100_000_000 == 0 { println!( "Processed {}M records ({:.03}s)",