mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
support .zstd, .xz and .bz2 compressed inputs
This commit is contained in:
parent
1af4aa6de9
commit
4f3d6a17ab
4 changed files with 80 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use ruzstd::frame_decoder::FrameDecoderError;
|
||||
use std::string::FromUtf8Error;
|
||||
use thiserror::Error;
|
||||
use zip::result::ZipError;
|
||||
|
|
@ -22,6 +23,8 @@ pub enum ReadError {
|
|||
Io(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
Zip(#[from] ZipError),
|
||||
#[error(transparent)]
|
||||
Zstd(#[from] FrameDecoderError),
|
||||
#[error("archive contains multiple files")]
|
||||
MultipleFiles,
|
||||
#[error("archive contains no files")]
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@ mod archive;
|
|||
|
||||
use crate::error::ReadError;
|
||||
use crate::logfile::archive::{Archive, ArchiveEntry, TarArchive, ZipArchive};
|
||||
use bzip2_rs::DecoderReader;
|
||||
use flate2::read::GzDecoder;
|
||||
use ruzstd::StreamingDecoder;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::{BufReader, Read};
|
||||
use xz2::read::XzDecoder;
|
||||
|
||||
pub struct LogFile {
|
||||
content: String,
|
||||
|
|
@ -13,6 +16,7 @@ pub struct LogFile {
|
|||
impl LogFile {
|
||||
pub fn open(path: &str) -> Result<LogFile, ReadError> {
|
||||
let file = File::open(path)?;
|
||||
let file = BufReader::new(file);
|
||||
if path.ends_with(".zip") {
|
||||
let mut zip = ZipArchive::new(file)?;
|
||||
let content = select_file(&mut zip)?;
|
||||
|
|
@ -23,6 +27,15 @@ impl LogFile {
|
|||
if let Some(path) = path.strip_suffix(".gz") {
|
||||
let decoder = GzDecoder::new(file);
|
||||
return Self::open_no_seek(path, decoder);
|
||||
} else if let Some(path) = path.strip_suffix(".xz") {
|
||||
let decoder = XzDecoder::new(file);
|
||||
return Self::open_no_seek(path, decoder);
|
||||
} else if let Some(path) = path.strip_suffix(".bz2") {
|
||||
let decoder = DecoderReader::new(file);
|
||||
return Self::open_no_seek(path, decoder);
|
||||
} else if let Some(path) = path.strip_suffix(".zst") {
|
||||
let decoder = StreamingDecoder::new(file)?;
|
||||
return Self::open_no_seek(path, decoder);
|
||||
}
|
||||
|
||||
Self::open_no_seek(path, Box::new(file))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue