mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 10:54:38 +00:00
remove null byte from string
This commit is contained in:
parent
b268b8e8ac
commit
100c4a189f
1 changed files with 5 additions and 2 deletions
|
@ -38,7 +38,7 @@ impl<R: std::io::Read> ReadExt for R {
|
|||
}
|
||||
|
||||
fn read_string(&mut self) -> Result<String, crate::Error> {
|
||||
Ok(match self.read_i32::<LE>()? {
|
||||
let mut buf = match self.read_i32::<LE>()? {
|
||||
size if size.is_negative() => {
|
||||
let mut buf = Vec::with_capacity(-size as usize);
|
||||
for _ in 0..buf.capacity() {
|
||||
|
@ -47,7 +47,10 @@ impl<R: std::io::Read> ReadExt for R {
|
|||
String::from_utf16(&buf)?
|
||||
}
|
||||
size => String::from_utf8(self.read_len(size as usize)?)?,
|
||||
})
|
||||
};
|
||||
// remove the null byte
|
||||
buf.pop();
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn read_len(&mut self, len: usize) -> Result<Vec<u8>, super::Error> {
|
||||
|
|
Loading…
Reference in a new issue