use std::collections::HashMap;
use std::io::{Cursor, Read};
use super::error::LoadError;
pub fn unzip_entries(bytes: &[u8]) -> Result<HashMap<String, Vec<u8>>, LoadError> {
let cursor = Cursor::new(bytes);
let mut archive = zip::ZipArchive::new(cursor).map_err(|e| LoadError::Zip(e.to_string()))?;
let mut entries = HashMap::with_capacity(archive.len());
for i in 0..archive.len() {
let mut entry = archive
.by_index(i)
.map_err(|e| LoadError::Zip(e.to_string()))?;
let path = entry.name().to_string();
let mut buf = Vec::with_capacity(entry.size() as usize);
entry
.read_to_end(&mut buf)
.map_err(|e| LoadError::Zip(e.to_string()))?;
entries.insert(path, buf);
}
Ok(entries)
}