use std::path::Path;
use crate::server::WRITING_FILES_BUF_LEN;
pub struct FileRSender<'a>{
pub path:&'a Path,
pub buffer_size_for_reading_from_file_and_writing_to_stream:usize,
pub range:Option<(Option<usize>,Option<usize>)>,
pub edit_each_chunk:Option<Box<dyn FnMut(&mut [u8] )+ Send >>,
pub content_disposition:Option<String>
}
impl <'a> FileRSender<'a> {
pub fn custom(path:&Path,
buffer_size_for_reading_from_file_and_writing_to_stream:usize,
)->FileRSender<'_>{
FileRSender {
path,
buffer_size_for_reading_from_file_and_writing_to_stream,
range:None,
edit_each_chunk:None,
content_disposition:None
}
}
pub fn new(path:&str)->FileRSender<'_>{
Self::custom(Path::new(path),WRITING_FILES_BUF_LEN)
}
pub fn set_edit_each_chunk(&mut self,callback:impl FnMut(&mut [u8]) + Send + 'static){
self.edit_each_chunk = Some(Box::new(callback));
}
pub fn set_bytes_range(&mut self,start:Option<usize>,end:Option<usize>){
self.range = Some((start,end));
}
pub fn set_content_disposition(&mut self,ct:&str){
self.content_disposition = Some(ct.to_string());
}
}