mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
add rar support
This commit is contained in:
parent
55444a3886
commit
14fb51c33d
6 changed files with 93 additions and 1 deletions
30
Cargo.lock
generated
30
Cargo.lock
generated
|
|
@ -925,6 +925,7 @@ dependencies = [
|
||||||
"tikv-jemallocator",
|
"tikv-jemallocator",
|
||||||
"time",
|
"time",
|
||||||
"tinystr",
|
"tinystr",
|
||||||
|
"unrar",
|
||||||
"xz2",
|
"xz2",
|
||||||
"zip",
|
"zip",
|
||||||
]
|
]
|
||||||
|
|
@ -1684,6 +1685,29 @@ version = "0.2.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unrar"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "92ec61343a630d2b50d13216dea5125e157d3fc180a7d3f447d22fe146b648fc"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"regex",
|
||||||
|
"unrar_sys",
|
||||||
|
"widestring",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unrar_sys"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b77675b883cfbe6bf41e6b7a5cd6008e0a83ba497de3d96e41a064bbeead765"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|
@ -1785,6 +1809,12 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "widestring"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd7cf3379ca1aac9eea11fba24fd7e315d621f8dfe35c8d7d2be8b793726e07d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ xz2 = "0.1.7"
|
||||||
bzip2-rs = "0.1.2"
|
bzip2-rs = "0.1.2"
|
||||||
ruzstd = "0.8.0"
|
ruzstd = "0.8.0"
|
||||||
sevenz-rust2 = "0.13.2"
|
sevenz-rust2 = "0.13.2"
|
||||||
|
unrar = "0.5.8"
|
||||||
dialoguer = "0.11.0"
|
dialoguer = "0.11.0"
|
||||||
indicatif = { version = "0.17.11", features = ["rayon"] }
|
indicatif = { version = "0.17.11", features = ["rayon"] }
|
||||||
csv = "1.3.1"
|
csv = "1.3.1"
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ pub enum ReadError {
|
||||||
Zstd(#[from] FrameDecoderError),
|
Zstd(#[from] FrameDecoderError),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
SevenZip(#[from] sevenz_rust2::Error),
|
SevenZip(#[from] sevenz_rust2::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
Rar(#[from] unrar::error::UnrarError),
|
||||||
#[error("archive contains no files")]
|
#[error("archive contains no files")]
|
||||||
NoFiles,
|
NoFiles,
|
||||||
#[error("log file contained non-utf8 characters: {0:#}")]
|
#[error("log file contained non-utf8 characters: {0:#}")]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod rar;
|
||||||
mod sevenzip;
|
mod sevenzip;
|
||||||
mod tar;
|
mod tar;
|
||||||
mod zip;
|
mod zip;
|
||||||
|
|
@ -6,6 +7,7 @@ use crate::error::ReadError;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
|
pub use rar::RarArchive;
|
||||||
pub use sevenzip::SevenZipArchive;
|
pub use sevenzip::SevenZipArchive;
|
||||||
pub use tar::TarArchive;
|
pub use tar::TarArchive;
|
||||||
pub use zip::ZipArchive;
|
pub use zip::ZipArchive;
|
||||||
|
|
|
||||||
52
src/logfile/archive/rar.rs
Normal file
52
src/logfile/archive/rar.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
use crate::error::ReadError;
|
||||||
|
use crate::logfile::archive::{Archive, ArchiveEntry};
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
pub struct RarArchive {
|
||||||
|
path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RarArchive {
|
||||||
|
pub fn new(path: &str) -> Result<Self, ReadError> {
|
||||||
|
Ok(RarArchive { path: path.into() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RarEntry {
|
||||||
|
archive: String,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ArchiveEntry for RarEntry {
|
||||||
|
fn name(&self) -> Cow<str> {
|
||||||
|
self.name.as_str().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract(self) -> Result<Vec<u8>, ReadError> {
|
||||||
|
let mut archive = unrar::Archive::new(&self.archive).open_for_processing()?;
|
||||||
|
while let Some(header) = archive.read_header()? {
|
||||||
|
if header.entry().filename.to_string_lossy() == self.name {
|
||||||
|
return Ok(header.read()?.0);
|
||||||
|
}
|
||||||
|
archive = header.skip()?;
|
||||||
|
}
|
||||||
|
Err(ReadError::NoFiles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Archive for RarArchive {
|
||||||
|
type Entry<'a> = RarEntry;
|
||||||
|
|
||||||
|
fn entries(&mut self) -> impl Iterator<Item = Self::Entry<'_>> {
|
||||||
|
unrar::Archive::new(&self.path)
|
||||||
|
.open_for_listing()
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.map(|header| RarEntry {
|
||||||
|
archive: self.path.clone(),
|
||||||
|
name: header.filename.to_string_lossy().into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,9 @@ mod archive;
|
||||||
pub mod logline;
|
pub mod logline;
|
||||||
|
|
||||||
use crate::error::ReadError;
|
use crate::error::ReadError;
|
||||||
use crate::logfile::archive::{Archive, ArchiveEntry, SevenZipArchive, TarArchive, ZipArchive};
|
use crate::logfile::archive::{
|
||||||
|
Archive, ArchiveEntry, RarArchive, SevenZipArchive, TarArchive, ZipArchive,
|
||||||
|
};
|
||||||
use bzip2_rs::DecoderReader;
|
use bzip2_rs::DecoderReader;
|
||||||
use csv::Reader;
|
use csv::Reader;
|
||||||
use dialoguer::Select;
|
use dialoguer::Select;
|
||||||
|
|
@ -40,6 +42,9 @@ impl LogFile {
|
||||||
} else if path.ends_with(".7z") {
|
} else if path.ends_with(".7z") {
|
||||||
let mut zip = SevenZipArchive::new(file)?;
|
let mut zip = SevenZipArchive::new(file)?;
|
||||||
return select_file(&mut zip);
|
return select_file(&mut zip);
|
||||||
|
} else if path.ends_with(".rar") {
|
||||||
|
let mut rar = RarArchive::new(path)?;
|
||||||
|
return select_file(&mut rar);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path) = path.strip_suffix(".gz") {
|
if let Some(path) = path.strip_suffix(".gz") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue