mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
don't hide the use of vec
This commit is contained in:
parent
c1811265d1
commit
6bd3be3aca
3 changed files with 5 additions and 10 deletions
|
@ -276,16 +276,13 @@ impl<W: Write + Seek> PakWriter<W> {
|
|||
self.writer
|
||||
}
|
||||
|
||||
pub fn write_file<R: Read>(&mut self, path: &str, reader: &mut R) -> Result<(), super::Error> {
|
||||
let mut data = vec![];
|
||||
reader.read_to_end(&mut data)?;
|
||||
|
||||
pub fn write_file(&mut self, path: &str, data: impl AsRef<[u8]>) -> Result<(), super::Error> {
|
||||
use sha1::{Digest, Sha1};
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(&data);
|
||||
|
||||
let offset = self.writer.stream_position()?;
|
||||
let len = data.len() as u64;
|
||||
let len = data.as_ref().len() as u64;
|
||||
|
||||
let entry = super::entry::Entry {
|
||||
offset,
|
||||
|
@ -307,7 +304,7 @@ impl<W: Write + Seek> PakWriter<W> {
|
|||
|
||||
self.pak.index.add_entry(path, entry);
|
||||
|
||||
self.writer.write_all(&data)?;
|
||||
self.writer.write_all(data.as_ref())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -172,9 +172,7 @@ fn test_write(_version: repak::Version, _file_name: &str, bytes: &[u8]) {
|
|||
|
||||
for path in pak_reader.files() {
|
||||
let data = pak_reader.get(&path, &mut reader).unwrap();
|
||||
pak_writer
|
||||
.write_file(&path, &mut std::io::Cursor::new(data))
|
||||
.unwrap();
|
||||
pak_writer.write_file(&path, data).unwrap();
|
||||
}
|
||||
|
||||
assert!(pak_writer.write_index().unwrap().into_inner() == reader.into_inner());
|
||||
|
|
|
@ -438,7 +438,7 @@ fn pack(args: ActionPack) -> Result<(), repak::Error> {
|
|||
if args.verbose {
|
||||
progress.println(format!("packing {}", &rel));
|
||||
}
|
||||
pak.write_file(rel, &mut BufReader::new(File::open(p)?))
|
||||
pak.write_file(rel, std::fs::read(p)?)
|
||||
})?;
|
||||
|
||||
pak.write_index()?;
|
||||
|
|
Loading…
Reference in a new issue