mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-08 04:25:31 +00:00
Early return when can't detect extension from magic numbers
This commit is contained in:
parent
552096acf0
commit
16acb98b6e
@ -126,10 +126,16 @@ pub fn try_infer_extension(path: &Path) -> Option<Extension> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let buf = {
|
let buf = {
|
||||||
let mut b = [0; 270];
|
let mut buf = [0; 270];
|
||||||
// Reading errors will just make the inferring fail so its safe to ignore
|
|
||||||
let _ = std::fs::File::open(&path).map(|mut f| std::io::Read::read(&mut f, &mut b));
|
// Error cause will be ignored, so use std::fs instead of fs_err
|
||||||
b
|
let result = std::fs::File::open(&path).map(|mut file| file.read(&mut buf));
|
||||||
|
|
||||||
|
// In case of file open or read failure, could not infer a extension
|
||||||
|
if result.is_err() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
buf
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::extension::CompressionFormat::*;
|
use crate::extension::CompressionFormat::*;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user