Skip to content

Commit 1c98e3b

Browse files
author
Devdutt Shenoi
committed
refactor: get_schemas_if_present
1 parent a9513c4 commit 1c98e3b

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/parseable/streams.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use std::{
2121
collections::HashMap,
2222
fs::{remove_file, write, File, OpenOptions},
23+
io::BufReader,
2324
num::NonZeroU32,
2425
path::{Path, PathBuf},
2526
process,
@@ -273,23 +274,13 @@ impl Stream {
273274
}
274275

275276
pub fn get_schemas_if_present(&self) -> Option<Vec<Schema>> {
276-
let Ok(dir) = self.data_path.read_dir() else {
277-
return None;
278-
};
279-
280277
let mut schemas: Vec<Schema> = Vec::new();
281278

282-
for file in dir.flatten() {
283-
if let Some(ext) = file.path().extension() {
284-
if ext.eq("schema") {
285-
let file = File::open(file.path()).expect("Schema File should exist");
279+
for path in self.schema_files() {
280+
let file = File::open(path).expect("Schema File should exist");
286281

287-
let schema = match serde_json::from_reader(file) {
288-
Ok(schema) => schema,
289-
Err(_) => continue,
290-
};
291-
schemas.push(schema);
292-
}
282+
if let Ok(schema) = serde_json::from_reader(BufReader::new(file)) {
283+
schemas.push(schema);
293284
}
294285
}
295286

0 commit comments

Comments
 (0)