Skip to content

Commit 01f3fb0

Browse files
feat: add save_media_file
1 parent 5ee8369 commit 01f3fb0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/file_conversion.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
use std::fs;
1+
use std::fs::{self, File};
22
use std::path::Path;
33
use crate::types::{MediaFile, TextFile};
4+
use std::io::Write;
5+
6+
7+
pub fn save_media_file(notification_from: &u8, file: &MediaFile) -> std::io::Result<()> {
8+
let dir_name = format!("cached_files_{}", notification_from);
9+
let dir_path = Path::new(&dir_name);
10+
fs::create_dir_all(dir_path)?;
11+
12+
let file_name = format!("{}_{}", file.id, file.title, );
13+
let file_path = dir_path.join(file_name);
14+
15+
let mut f = File::create(file_path)?;
16+
for chunk in &file.content {
17+
f.write_all(chunk)?;
18+
}
19+
Ok(())
20+
}
421

522
/// Converts a file path into a `MediaFile`.
623
///

0 commit comments

Comments
 (0)