Use right buffer type for inflate and deflate. fixes #1
Using a String for zlib decoder/encoder output doesn't work because it can only hold valid utf8. Read into a Vec<u8> instead and construct a lua string from it.
This commit is contained in:
1 parent
50b4450c8b
commit
e52aed0890
1 file changed
+14
-6
+14
-6
@@ -245,9 +245,13 @@ fn inflate(l: &Lua, compressed: LuaString) -> LuaResult<MultiValue> {
|
||||
}
|
||||
|
||||
let mut decoder = ZlibDecoder::new(compressed_bytes);
|
||||
let mut decompressed = String::new();
|
||||
match decoder.read_to_string(&mut decompressed) {
|
||||
Ok(_) => Ok(decompressed.into_lua_multi(l).unwrap()),
|
||||
let mut decompressed = Vec::new();
|
||||
match decoder.read_to_end(&mut decompressed) {
|
||||
Ok(_) => Ok(l
|
||||
.create_string(&decompressed)
|
||||
.unwrap()
|
||||
.into_lua_multi(l)
|
||||
.unwrap()),
|
||||
Err(e) => Ok((Value::Nil, e.to_string()).into_lua_multi(l).unwrap()),
|
||||
}
|
||||
}
|
||||
@@ -263,9 +267,13 @@ fn deflate(l: &Lua, uncompressed: LuaString) -> LuaResult<MultiValue> {
|
||||
}
|
||||
|
||||
let mut encoder = ZlibEncoder::new(uncompressed_bytes, Compression::fast());
|
||||
let mut compressed = String::new();
|
||||
match encoder.read_to_string(&mut compressed) {
|
||||
Ok(_) => Ok(compressed.into_lua_multi(l).unwrap()),
|
||||
let mut compressed = Vec::new();
|
||||
match encoder.read_to_end(&mut compressed) {
|
||||
Ok(_) => Ok(l
|
||||
.create_string(&compressed)
|
||||
.unwrap()
|
||||
.into_lua_multi(l)
|
||||
.unwrap()),
|
||||
Err(e) => Ok((Value::Nil, e.to_string()).into_lua_multi(l).unwrap()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user