comparison formats/src/th06/pbg3.rs @ 761:f506ad5c9b17

formats: Replace unwrap() with proper io::Error.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 06 Jan 2021 01:47:06 +0100
parents eba9a3d0c484
children ccb04468c5fa
comparison
equal deleted inserted replaced
760:eba9a3d0c484 761:f506ad5c9b17
118 let unknown_2 = bitstream.read_u32()?; 118 let unknown_2 = bitstream.read_u32()?;
119 let checksum = bitstream.read_u32()?; // Checksum of *compressed data* 119 let checksum = bitstream.read_u32()?; // Checksum of *compressed data*
120 let offset = bitstream.read_u32()?; 120 let offset = bitstream.read_u32()?;
121 let size = bitstream.read_u32()?; 121 let size = bitstream.read_u32()?;
122 let name = bitstream.read_string(255)?; 122 let name = bitstream.read_string(255)?;
123 // XXX: no unwrap! 123 let name = String::from_utf8(name).map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
124 let name = String::from_utf8(name).unwrap();
125 entries.insert(name, (unknown_1, unknown_2, checksum, offset, size)); 124 entries.insert(name, (unknown_1, unknown_2, checksum, offset, size));
126 } 125 }
127 126
128 Ok(PBG3::new(entries, bitstream)) 127 Ok(PBG3::new(entries, bitstream))
129 } 128 }
133 self.entries.keys() 132 self.entries.keys()
134 } 133 }
135 134
136 /// Read a single file from this PBG3 archive. 135 /// Read a single file from this PBG3 archive.
137 pub fn get_file(&mut self, filename: &str, check: bool) -> io::Result<Vec<u8>> { 136 pub fn get_file(&mut self, filename: &str, check: bool) -> io::Result<Vec<u8>> {
138 // XXX: no unwrap! 137 let (_unknown_1, _unknown_2, checksum, offset, size) =
139 let (_unknown_1, _unknown_2, checksum, offset, size) = self.entries.get(filename).unwrap(); 138 self.entries.get(filename)
139 .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, format!("File not found in PBG3: {}", filename)))?;
140 self.bitstream.seek(io::SeekFrom::Start(*offset as u64))?; 140 self.bitstream.seek(io::SeekFrom::Start(*offset as u64))?;
141 let data = lzss::decompress(&mut self.bitstream.bitstream, *size as usize, 0x2000, 13, 4, 3)?; 141 let data = lzss::decompress(&mut self.bitstream.bitstream, *size as usize, 0x2000, 13, 4, 3)?;
142 if check { 142 if check {
143 // Verify the checksum. 143 // Verify the checksum.
144 let compressed_size = self.bitstream.tell()? as u32 - *offset; 144 let compressed_size = self.bitstream.tell()? as u32 - *offset;