simplify pxar module structure

This commit is contained in:
Dietmar Maurer 2019-03-15 08:24:32 +01:00
parent 1ef46b81d3
commit 3dbfe5b142
6 changed files with 22 additions and 18 deletions

View File

@ -12,8 +12,7 @@ use serde_json::{Value};
use std::io::Write;
use std::path::{Path, PathBuf};
use proxmox_backup::pxar::encoder::*;
use proxmox_backup::pxar::decoder::*;
use proxmox_backup::pxar;
fn print_filenames(
param: Value,
@ -26,7 +25,7 @@ fn print_filenames(
let mut reader = std::io::BufReader::new(file);
let mut decoder = PxarDecoder::new(&mut reader);
let mut decoder = pxar::SequentialDecoder::new(&mut reader);
let stdout = std::io::stdout();
let mut out = stdout.lock();
@ -48,7 +47,7 @@ fn dump_archive(
let mut reader = std::io::BufReader::new(file);
let mut decoder = PxarDecoder::new(&mut reader);
let mut decoder = pxar::SequentialDecoder::new(&mut reader);
let stdout = std::io::stdout();
let mut out = stdout.lock();
@ -75,7 +74,7 @@ fn extract_archive(
let mut reader = std::io::BufReader::new(file);
let mut decoder = PxarDecoder::new(&mut reader);
let mut decoder = pxar::SequentialDecoder::new(&mut reader);
decoder.restore(Path::new(target), & |path| {
if verbose {
@ -110,7 +109,7 @@ fn create_archive(
let mut writer = std::io::BufWriter::with_capacity(1024*1024, file);
PxarEncoder::encode(source, &mut dir, &mut writer, all_file_systems, verbose)?;
pxar::Encoder::encode(source, &mut dir, &mut writer, all_file_systems, verbose)?;
writer.flush()?;

View File

@ -11,7 +11,7 @@ use nix::fcntl::OFlag;
use nix::sys::stat::Mode;
use nix::dir::Dir;
use crate::pxar::encoder::*;
use crate::pxar;
/// Stream implementation to encode and upload .pxar archives.
///
@ -44,7 +44,7 @@ impl PxarBackupStream {
let child = thread::spawn(move|| {
let mut writer = unsafe { std::fs::File::from_raw_fd(tx) };
if let Err(err) = PxarEncoder::encode(path, &mut dir, &mut writer, all_file_systems, verbose) {
if let Err(err) = pxar::Encoder::encode(path, &mut dir, &mut writer, all_file_systems, verbose) {
eprintln!("pxar encode failed - {}", err);
}
});

View File

@ -5,7 +5,7 @@ use std::os::unix::io::FromRawFd;
use std::path::{Path, PathBuf};
use std::io::Write;
use crate::pxar::decoder::*;
use crate::pxar;
/// Writer implementation to deccode a .pxar archive (download).
@ -31,7 +31,7 @@ impl PxarDecodeWriter {
let child = thread::spawn(move|| {
let mut reader = unsafe { std::fs::File::from_raw_fd(rx) };
let mut decoder = PxarDecoder::new(&mut reader);
let mut decoder = pxar::SequentialDecoder::new(&mut reader);
if let Err(err) = decoder.restore(&base, & |path| {
if verbose {

View File

@ -38,8 +38,13 @@
//! * ...
//! * GOODBYE -- lookup table at the end of a list of directory entries
pub mod binary_search_tree;
pub mod format_definition;
pub mod encoder;
pub mod decoder;
mod binary_search_tree;
mod format_definition;
pub use format_definition::*;
mod encoder;
pub use encoder::*;
mod decoder;
pub use decoder::*;

View File

@ -22,14 +22,14 @@ use nix::errno::Errno;
use nix::NixPath;
// This one need Read, but works without Seek
pub struct PxarDecoder<'a, R: Read> {
pub struct SequentialDecoder<'a, R: Read> {
reader: &'a mut R,
skip_buffer: Vec<u8>,
}
const HEADER_SIZE: u64 = std::mem::size_of::<CaFormatHeader>() as u64;
impl <'a, R: Read> PxarDecoder<'a, R> {
impl <'a, R: Read> SequentialDecoder<'a, R> {
pub fn new(reader: &'a mut R) -> Self {
let skip_buffer = vec![0u8; 64*1024];

View File

@ -27,7 +27,7 @@ use nix::sys::stat::FileStat;
/// maximum memory usage.
pub const MAX_DIRECTORY_ENTRIES: usize = 256*1024;
pub struct PxarEncoder<'a, W: Write> {
pub struct Encoder<'a, W: Write> {
current_path: PathBuf, // used for error reporting
writer: &'a mut W,
writer_pos: usize,
@ -38,7 +38,7 @@ pub struct PxarEncoder<'a, W: Write> {
verbose: bool,
}
impl <'a, W: Write> PxarEncoder<'a, W> {
impl <'a, W: Write> Encoder<'a, W> {
pub fn encode(
path: PathBuf,