cursive_image/image/
source.rs1use super::stream::*;
2
3use std::{fs::*, io, path::*};
4
5pub enum ImageSource {
11 Owned(Vec<u8>, bool),
13
14 LocalFile(PathBuf, bool),
16
17 Stream(ImageStreamRef),
19}
20
21impl ImageSource {
22 pub fn into_owned(&mut self) -> io::Result<()> {
24 match self {
25 Self::LocalFile(path, compressed) => *self = Self::Owned(read(path)?, *compressed),
26
27 Self::Stream(stream) => {
28 let (mut reader, compressed) = stream.open()?;
29 let mut data = Vec::default();
30 reader.read_to_end(&mut data)?;
31 *self = Self::Owned(data, compressed);
32 }
33
34 _ => {}
35 }
36
37 Ok(())
38 }
39}