mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 00:15:17 +00:00
Add support for multiple files types
This commit is contained in:
@ -7,4 +7,7 @@ pub mod user_data_utils;
|
||||
pub mod virtual_directories_utils;
|
||||
pub mod date_utils;
|
||||
pub mod string_utils;
|
||||
pub mod pdf_utils;
|
||||
pub mod pdf_utils;
|
||||
pub mod mp3_utils;
|
||||
pub mod mp4_utils;
|
||||
pub mod zip_utils;
|
16
src/utils/mp3_utils.rs
Normal file
16
src/utils/mp3_utils.rs
Normal file
@ -0,0 +1,16 @@
|
||||
//! # MP3 utilities
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
/// Check out whether a file is a valid MP3 file or not
|
||||
pub fn is_valid_mp3(file: &[u8]) -> bool {
|
||||
let res = mp3_metadata::read_from_slice(file);
|
||||
|
||||
match res {
|
||||
Ok(_) => true,
|
||||
Err(e) => {
|
||||
eprintln!("Error while parsing MP3 file ! {:#?}", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
17
src/utils/mp4_utils.rs
Normal file
17
src/utils/mp4_utils.rs
Normal file
@ -0,0 +1,17 @@
|
||||
//! # MP utilities
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
/// Check out whether an MP4 file is valid or not
|
||||
pub fn is_valid_mp4(file: &[u8]) -> bool {
|
||||
let cursor = std::io::Cursor::new(file);
|
||||
let reader = mp4::Mp4Reader::read_header(cursor, file.len() as u64);
|
||||
|
||||
match reader {
|
||||
Ok(_) => true,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to read MP4! {:#?}", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
16
src/utils/zip_utils.rs
Normal file
16
src/utils/zip_utils.rs
Normal file
@ -0,0 +1,16 @@
|
||||
//! # ZIP utilities
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
/// Check out whether a given file is a valid ZIP archive or not
|
||||
pub fn is_valid_zip(file: &[u8]) -> bool {
|
||||
let cursor = std::io::Cursor::new(file);
|
||||
|
||||
match zip::ZipArchive::new(cursor) {
|
||||
Ok(_) => true,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to read ZIP archive! {:#?}", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user