Skip to content

Commit

Permalink
Remove mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Aug 13, 2023
1 parent 4607286 commit 60ea025
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
7 changes: 2 additions & 5 deletions lib/src/archive/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod options;
mod read;
mod write;

pub(crate) use self::read::MutexRead;
pub use self::{builder::*, header::*, meta::*, name::*, options::*};
use self::{private::*, read::*, write::*};
use crate::{
Expand Down Expand Up @@ -39,7 +38,7 @@ pub trait Entry: SealedIntoChunks {

/// Readable archive entry.
pub trait ReadEntry: Entry {
type Reader: Read + Sync + Send;
type Reader: Read;
fn header(&self) -> &EntryHeader;
fn metadata(&self) -> &Metadata;
fn into_reader(self, option: ReadOption) -> io::Result<Self::Reader>;
Expand Down Expand Up @@ -437,9 +436,7 @@ fn decompress_reader<'r, R: Read>(
Ok(match compression {
Compression::No => DecompressReader::Store(reader),
Compression::Deflate => DecompressReader::Deflate(flate2::read::ZlibDecoder::new(reader)),
Compression::ZStandard => {
DecompressReader::ZStd(MutexRead::new(zstd::Decoder::new(reader)?))
}
Compression::ZStandard => DecompressReader::ZStd(zstd::Decoder::new(reader)?),
Compression::XZ => DecompressReader::Xz(xz2::read::XzDecoder::new(reader)),
})
}
Expand Down
17 changes: 0 additions & 17 deletions lib/src/archive/entry/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ use camellia::Camellia256;
use crypto_common::BlockSizeUser;
use std::io;
use std::io::Read;
use std::sync::Mutex;

// NOTE: zstd crate not support Sync + Send trait
pub(crate) struct MutexRead<R: Read>(Mutex<R>);

impl<R: Read> MutexRead<R> {
pub(super) fn new(reader: R) -> Self {
Self(Mutex::new(reader))
}
}

impl<R: Read> Read for MutexRead<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let reader = self.0.get_mut().unwrap();
reader.read(buf)
}
}

pub(super) fn aes_ctr_cipher_reader<R: Read>(
mut reader: R,
Expand Down
3 changes: 1 addition & 2 deletions lib/src/compress.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::archive::MutexRead;
use crate::io::{TryIntoInner, TryIntoInnerWrite};
use flate2::{read::ZlibDecoder, write::ZlibEncoder};
use std::io::{BufReader, Read, Result, Write};
Expand Down Expand Up @@ -52,7 +51,7 @@ impl<'w, W: Write> TryIntoInnerWrite<W> for CompressionWriter<'w, W> {}
pub(crate) enum DecompressReader<'r, R: Read> {
Store(R),
Deflate(ZlibDecoder<R>),
ZStd(MutexRead<ZStdDecoder<'r, BufReader<R>>>),
ZStd(ZStdDecoder<'r, BufReader<R>>),
Xz(XzDecoder<R>),
}

Expand Down

0 comments on commit 60ea025

Please sign in to comment.