mirror of
git://git.proxmox.com/git/pxar.git
synced 2024-12-22 21:33:50 +03:00
encoder: implement a larger shared file copy buffer
In the future we can give it a size. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
f3ac1c5125
commit
79e3f621c3
@ -2,11 +2,13 @@
|
|||||||
//!
|
//!
|
||||||
//! This is the implementation used by both the synchronous and async pxar wrappers.
|
//! This is the implementation used by both the synchronous and async pxar wrappers.
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::mem::{forget, size_of, size_of_val, take};
|
use std::mem::{forget, size_of, size_of_val, take};
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
use std::rc::Rc;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use endian_trait::Endian;
|
use endian_trait::Endian;
|
||||||
@ -229,6 +231,10 @@ pub(crate) struct EncoderImpl<'a, T: SeqWrite + 'a> {
|
|||||||
state: EncoderState,
|
state: EncoderState,
|
||||||
parent: Option<&'a mut EncoderState>,
|
parent: Option<&'a mut EncoderState>,
|
||||||
finished: bool,
|
finished: bool,
|
||||||
|
|
||||||
|
/// Since only the "current" entry can be actively writing files, we share the file copy
|
||||||
|
/// buffer.
|
||||||
|
file_copy_buffer: Rc<RefCell<Vec<u8>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: SeqWrite + 'a> Drop for EncoderImpl<'a, T> {
|
impl<'a, T: SeqWrite + 'a> Drop for EncoderImpl<'a, T> {
|
||||||
@ -256,6 +262,7 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
|
|||||||
state: EncoderState::default(),
|
state: EncoderState::default(),
|
||||||
parent: None,
|
parent: None,
|
||||||
finished: false,
|
finished: false,
|
||||||
|
file_copy_buffer: Rc::new(RefCell::new(crate::util::vec_new(1024 * 1024))),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.encode_metadata(metadata).await?;
|
this.encode_metadata(metadata).await?;
|
||||||
@ -329,10 +336,11 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
|
|||||||
file_size: u64,
|
file_size: u64,
|
||||||
content: &mut dyn SeqRead,
|
content: &mut dyn SeqRead,
|
||||||
) -> io::Result<LinkOffset> {
|
) -> io::Result<LinkOffset> {
|
||||||
|
let buf = Rc::clone(&self.file_copy_buffer);
|
||||||
let mut file = self.create_file(metadata, file_name, file_size).await?;
|
let mut file = self.create_file(metadata, file_name, file_size).await?;
|
||||||
let mut buf = crate::util::vec_new(4096);
|
let mut buf = buf.borrow_mut();
|
||||||
loop {
|
loop {
|
||||||
let got = decoder::seq_read(&mut *content, &mut buf).await?;
|
let got = decoder::seq_read(&mut *content, &mut buf[..]).await?;
|
||||||
if got == 0 {
|
if got == 0 {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -501,6 +509,7 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
|
|||||||
},
|
},
|
||||||
parent: Some(&mut self.state),
|
parent: Some(&mut self.state),
|
||||||
finished: false,
|
finished: false,
|
||||||
|
file_copy_buffer: Rc::clone(&self.file_copy_buffer),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user