new release! 0u0
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing

also i increased BUF_SIZE to 8192 bytes
This commit is contained in:
Lynne Megido 2021-04-14 17:27:44 +10:00
parent 383f6a30f2
commit 9c8be183d9
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
4 changed files with 43 additions and 17 deletions

View File

@ -2,15 +2,19 @@
Dates are given in YYYY-MM-DD format.
## v0.2
### v0.2.12 (2021-???)
- Much better README.md
### v0.2.12 (2021-04-14)
#### Features
- Added Text extension set
- Better documentation for command line arguments
#### Bugfixes
- Fixed a very minor output bug relating to scanning symlinked directories
- Better detection for pre-OOXML Office files
#### Other
- Much better README.md
- Added more stuff to test.py
- PKGBUILD for Arch-based distros
- Added Text extension set
- More test coverage
- Fixed a very minor output bug relating to scanning symlinked directories
- Better detection for a specific formats (pre-OOXML Office, EXE, DLL)
- Doubled BUF_SIZE
### v0.2.11 (2021-04-04)
#### Features

33
Cargo.lock generated
View File

@ -29,6 +29,12 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cached"
version = "0.23.0"
@ -39,6 +45,16 @@ dependencies = [
"once_cell",
]
[[package]]
name = "cfb"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca453e8624711b2f0f4eb47076a318feda166252a827ee25d067b43de83dcba0"
dependencies = [
"byteorder",
"uuid",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -177,7 +193,7 @@ dependencies = [
[[package]]
name = "fif"
version = "0.2.11"
version = "0.2.12"
dependencies = [
"cached",
"cfg-if",
@ -250,9 +266,12 @@ dependencies = [
[[package]]
name = "infer"
version = "0.3.7"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "865e8a58ae8e24d2c4412c31344afa1d302a3740ad67528c10f50d6876cdcf55"
checksum = "f92b41dab759f9e8427c03f519c344a14655490b8db548dac1e57a75b3258391"
dependencies = [
"cfb",
]
[[package]]
name = "instant"
@ -321,7 +340,7 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "git+https://github.com/Lynnesbian/mime_guess#55fe99663a1b78ad5f50ffe1a9aaeb65fb2cb4ca"
source = "git+https://github.com/Lynnesbian/mime_guess#28633a9936a9c3eb29cf85e99899e35ddd63d9c1"
dependencies = [
"mime",
"unicase",
@ -654,6 +673,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]]
name = "vec_map"
version = "0.8.2"

View File

@ -1,7 +1,7 @@
[package]
name = "fif"
description = "A command-line tool for detecting and optionally correcting files with incorrect extensions."
version = "0.2.11"
version = "0.2.12"
authors = ["Lynnesbian <lynne@bune.city>"]
edition = "2018"
license = "GPL-3.0-or-later"
@ -29,7 +29,7 @@ log = "0.4.14"
mime_guess = "2.0.3"
snailquote = "0.3.0"
once_cell = "1.7.2"
infer = "0.3.6"
infer = "0.4.0"
rayon = { version = "1.5.0", optional = true }
exitcode = "1.1.2"
cfg-if = "1.0.0"

View File

@ -20,16 +20,14 @@ use crate::string_type::String;
pub const INITIAL_BUF_SIZE: usize = 128;
/// The number of bytes to read if the file couldn't be identified from its first [`INITIAL_BUF_SIZE`] bytes.
pub const BUF_SIZE: usize = 4096;
pub const BUF_SIZE: usize = 8192;
/// Tries to identify the mimetype of a file from a given path.
pub fn mime_type<T: MimeDb>(db: &T, path: &Path) -> io::Result<Option<Mime>> {
let mut buffer = [0; INITIAL_BUF_SIZE];
let mut file = File::open(path)?;
// this lint can be ignored: it's okay if the file isn't long enough to fill the buffer, as we only care about the
// first few bytes for the purpose of mime sniffing
#[allow(clippy::unused_io_amount)]
// read a small amount to start with
file.read(&mut buffer)?;
let r = db.get_type(&buffer).filter(|mime|
@ -43,8 +41,7 @@ pub fn mime_type<T: MimeDb>(db: &T, path: &Path) -> io::Result<Option<Mime>> {
// doc/ppt/xls files are a subset of what's known as an "OLE2 compound document storage", at least according to
// shared-mime-info. if a pre-OOXML era MS office file is scanned and identified as x-ole-storage, reading further
// will allow it to be detected correctly as the appropriate filetype.
&& mime != &Mime::from_str("application/x-ole-storage").unwrap()
);
&& mime != &Mime::from_str("application/x-ole-storage").unwrap());
if r.is_some() {
return Ok(r);