-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flatimage): integrate flatimage using remote files
- Loading branch information
Showing
5 changed files
with
80 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::{ | ||
fs::File, | ||
io::{BufReader, Read}, | ||
}; | ||
|
||
use super::constant::{APPIMAGE_MAGIC_BYTES, ELF_MAGIC_BYTES, FLATIMAGE_MAGIC_BYTES}; | ||
|
||
pub enum FileType { | ||
AppImage, | ||
FlatImage, | ||
ELF, | ||
Unknown, | ||
} | ||
|
||
pub fn get_file_type(file: &mut BufReader<File>) -> FileType { | ||
let mut magic_bytes = [0u8; 12]; | ||
if file.read_exact(&mut magic_bytes).is_ok() { | ||
if magic_bytes[8..] == APPIMAGE_MAGIC_BYTES { | ||
return FileType::AppImage; | ||
} else if magic_bytes[8..] == FLATIMAGE_MAGIC_BYTES { | ||
return FileType::FlatImage; | ||
} else if magic_bytes[..4] == ELF_MAGIC_BYTES { | ||
return FileType::ELF; | ||
} else { | ||
return FileType::Unknown; | ||
} | ||
} | ||
FileType::Unknown | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod color; | ||
pub mod config; | ||
pub mod constant; | ||
pub mod file; | ||
pub mod health; | ||
pub mod log; | ||
pub mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters