mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Change vec<u8> to BufReader
Former-commit-id: 0e91de7976357c96ac58e4f4293c680b9ab98155
This commit is contained in:
committed by
Joshua Barretto
parent
70a7c78c50
commit
b01a94e384
@ -5,6 +5,7 @@ use std::{
|
|||||||
any::Any,
|
any::Any,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs::File,
|
fs::File,
|
||||||
|
io::BufReader,
|
||||||
io::Read,
|
io::Read,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
@ -74,13 +75,17 @@ pub trait Asset: Send + Sync + Sized {
|
|||||||
|
|
||||||
impl Asset for DynamicImage {
|
impl Asset for DynamicImage {
|
||||||
fn load(specifier: &str) -> Result<Self, Error> {
|
fn load(specifier: &str) -> Result<Self, Error> {
|
||||||
Ok(image::load_from_memory(load_from_path(specifier)?.as_slice()).unwrap())
|
let mut buf = Vec::new();
|
||||||
|
load_from_path(specifier)?.read_to_end(&mut buf)?;
|
||||||
|
Ok(image::load_from_memory(&buf).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Asset for DotVoxData {
|
impl Asset for DotVoxData {
|
||||||
fn load(specifier: &str) -> Result<Self, Error> {
|
fn load(specifier: &str) -> Result<Self, Error> {
|
||||||
Ok(dot_vox::load_bytes(load_from_path(specifier)?.as_slice()).unwrap())
|
let mut buf = Vec::new();
|
||||||
|
load_from_path(specifier)?.read_to_end(&mut buf)?;
|
||||||
|
Ok(dot_vox::load_bytes(&buf).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +109,9 @@ fn try_open_with_path(name: &str) -> Option<File> {
|
|||||||
.find_map(|ref filename| File::open(filename).ok())
|
.find_map(|ref filename| File::open(filename).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_from_path(name: &str) -> Result<Vec<u8>, Error> {
|
pub fn load_from_path(name: &str) -> Result<BufReader<File>, Error> {
|
||||||
match try_open_with_path(name) {
|
match try_open_with_path(name) {
|
||||||
Some(mut f) => {
|
Some(mut f) => Ok(BufReader::new(f)),
|
||||||
let mut content = Vec::<u8>::new();
|
|
||||||
f.read_to_end(&mut content)?;
|
|
||||||
Ok(content)
|
|
||||||
}
|
|
||||||
None => Err(Error::NotFound(name.to_owned())),
|
None => Err(Error::NotFound(name.to_owned())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ use conrod_core::{
|
|||||||
};
|
};
|
||||||
use graphic::Id as GraphicId;
|
use graphic::Id as GraphicId;
|
||||||
use scale::Scale;
|
use scale::Scale;
|
||||||
|
use std::io::Read;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use util::{linear_to_srgb, srgb_to_linear};
|
use util::{linear_to_srgb, srgb_to_linear};
|
||||||
@ -73,9 +74,9 @@ impl DrawCommand {
|
|||||||
pub struct Font(text::Font);
|
pub struct Font(text::Font);
|
||||||
impl assets::Asset for Font {
|
impl assets::Asset for Font {
|
||||||
fn load(specifier: &str) -> Result<Self, assets::Error> {
|
fn load(specifier: &str) -> Result<Self, assets::Error> {
|
||||||
Ok(Font(
|
let mut buf = Vec::new();
|
||||||
text::Font::from_bytes(assets::load_from_path(specifier)?).unwrap(),
|
assets::load_from_path(specifier)?.read_to_end(&mut buf)?;
|
||||||
))
|
Ok(Font(text::Font::from_bytes(buf.clone()).unwrap()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user