mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-16 17:51:29 +10:00
feat: performance improvements, fix zip
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
use std::{
|
||||
fmt::Debug, io::{Read, Seek, SeekFrom}
|
||||
fmt::Debug,
|
||||
io::{Read, Seek, SeekFrom},
|
||||
};
|
||||
|
||||
use dyn_clone::DynClone;
|
||||
use tokio::io::{self, AsyncRead};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -27,12 +29,11 @@ pub trait MinimumFileObject: Read + Send + Skippable {}
|
||||
impl<T: Read + Send + Seek> MinimumFileObject for T {}
|
||||
|
||||
// Intentionally not a generic, because of types in read_file
|
||||
pub struct ReadToAsyncRead {
|
||||
pub inner: Box<(dyn Read + Send)>,
|
||||
pub backend: Box<(dyn VersionBackend + Send)>,
|
||||
pub struct ReadToAsyncRead<'a> {
|
||||
pub inner: Box<dyn Read + Send + 'a>,
|
||||
}
|
||||
|
||||
impl AsyncRead for ReadToAsyncRead {
|
||||
impl<'a> AsyncRead for ReadToAsyncRead<'a> {
|
||||
fn poll_read(
|
||||
mut self: std::pin::Pin<&mut Self>,
|
||||
_cx: &mut std::task::Context<'_>,
|
||||
@ -40,13 +41,16 @@ impl AsyncRead for ReadToAsyncRead {
|
||||
) -> std::task::Poll<io::Result<()>> {
|
||||
let mut read_buf = [0u8; 8192];
|
||||
let var_name = self.inner.read(&mut read_buf).unwrap();
|
||||
let amount = var_name;
|
||||
let amount = var_name.min(buf.remaining());
|
||||
buf.put_slice(&read_buf[0..amount]);
|
||||
std::task::Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait VersionBackend {
|
||||
pub trait VersionBackend: DynClone {
|
||||
fn list_files(&mut self) -> Vec<VersionFile>;
|
||||
fn reader(&mut self, file: &VersionFile) -> Option<Box<(dyn MinimumFileObject)>>;
|
||||
fn peek_file(&mut self, sub_path: String) -> Option<VersionFile>;
|
||||
fn reader(&mut self, file: &VersionFile) -> Option<Box<dyn MinimumFileObject + '_>>;
|
||||
}
|
||||
|
||||
dyn_clone::clone_trait_object!(VersionBackend);
|
||||
Reference in New Issue
Block a user