mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-16 07:12:43 +00:00
Integration: start-screen previews read only the zip directory and the preview entry
This commit is contained in:
1 parent
94d21edfa1
commit
e8aadde385
2 files changed
+11
-2
No files matched your search
@@ -409,8 +409,8 @@ pub struct RecentPreview {
|
||||
pub fn recent_preview(path: &str) -> Option<RecentPreview> {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let bytes = crate::io::read(path).ok()?;
|
||||
let png = designcraft_format::read_preview(std::io::Cursor::new(bytes))?;
|
||||
// Only the zip directory and the preview entry are read, not the whole document.
|
||||
let png = designcraft_format::read_preview(std::io::BufReader::new(crate::io::open(path).ok()?))?;
|
||||
let img = designcraft_images::decode_rgba(&png)?;
|
||||
let (width, height) = img.dimensions();
|
||||
Some(RecentPreview { width, height, rgba: img.into_raw() })
|
||||
|
||||
@@ -37,6 +37,15 @@ pub fn read_capped(path: impl AsRef<Path>, cap: u64) -> std::io::Result<Vec<u8>>
|
||||
Ok(b)
|
||||
}
|
||||
|
||||
/// The file at `path` opened for reading, inside the automation read root when there is one, for
|
||||
/// callers that read only part of it. A refused path is a `PermissionDenied` error carrying the
|
||||
/// roots' message.
|
||||
pub fn open(path: impl AsRef<Path>) -> std::io::Result<std::fs::File> {
|
||||
let path = path.as_ref();
|
||||
crate::file_access::check_read(path).map_err(|e| std::io::Error::new(std::io::ErrorKind::PermissionDenied, e))?;
|
||||
std::fs::File::open(path)
|
||||
}
|
||||
|
||||
/// The text of the file at `path`, inside the automation read root when there is one.
|
||||
pub fn read_to_string(path: impl AsRef<Path>) -> Result<String, String> {
|
||||
let path = path.as_ref();
|
||||
|
||||
Reference in new issue
Block a user