aruna_file/
transformer.rs1use crate::notifications::{Message, Response};
2use anyhow::Result;
3use async_channel::{Receiver, Sender};
4
5#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
6pub enum TransformerType {
7 Unspecified,
8 ReadWriter,
9 All,
10 AsyncSenderSink,
11 ZstdCompressor,
12 GzipCompressor,
13 ZstdDecompressor,
14 ChaCha20Encrypt,
15 ChaCha20Decrypt,
16 Filter,
17 FooterGenerator,
18 HyperSink,
19 SizeProbe,
20 TarEncoder,
21 TarDecoder,
22 WriterSink,
23 Hashing,
24 ZipEncoder,
25}
26
27#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
28pub struct FileContext {
29 pub file_name: String,
31 pub input_size: u64,
33 pub file_size: u64,
35 pub file_path: Option<String>,
37 pub uid: Option<u64>,
39 pub gid: Option<u64>,
41 pub mode: Option<u32>,
43 pub mtime: Option<u64>,
45 pub skip_decompression: bool,
47 pub skip_decryption: bool,
49 pub encryption_key: Option<Vec<u8>>,
51 pub is_dir: bool,
53 pub is_symlink: bool,
55}
56
57impl FileContext {
58 #[tracing::instrument(level = "trace", skip(self))]
59 pub fn get_path(&self) -> String {
60 match &self.file_path {
61 Some(p) => p.clone() + "/" + &self.file_name,
62 None => self.file_name.clone(),
63 }
64 }
65}
66
67pub trait Sink: Transformer {}
69
70#[async_trait::async_trait]
71pub trait ReadWriter {
72 async fn process(&mut self) -> Result<()>;
73 async fn announce_all(&mut self, message: Message) -> Result<()>;
74 async fn add_file_context_receiver(&mut self, rx: Receiver<(FileContext, bool)>) -> Result<()>;
75}
76
77#[async_trait::async_trait]
78pub trait Transformer {
79 async fn process_bytes(
80 &mut self,
81 buf: &mut bytes::BytesMut,
82 finished: bool,
83 should_flush: bool,
84 ) -> Result<bool>;
85 #[allow(unused_variables)]
86 async fn notify(&mut self, message: &Message) -> Result<Response> {
87 Ok(Response::Ok)
88 }
89 #[allow(unused_variables)]
90 fn add_sender(&mut self, s: Sender<Message>) {}
91 #[allow(unused_variables)]
92 fn get_type(&self) -> TransformerType {
93 TransformerType::Unspecified
94 }
95}