From 9fef9aa8f12c6b094afa41801fdc9e490fc44454 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Sun, 3 Apr 2016 11:20:31 +0100 Subject: [PATCH] Support connecting to offline mode servers --- protocol/src/protocol/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 61f9b0a..472d95b 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -739,6 +739,9 @@ impl Conn { 0 }; if self.compression_threshold >= 0 && buf.len() as i32 > self.compression_threshold { + if self.compression_write.is_none() { + self.compression_write = Some(ZlibEncoder::new(io::Cursor::new(Vec::new()), flate2::Compression::Default)); + } extra = 0; let uncompressed_size = buf.len(); let mut new = Vec::new(); @@ -766,6 +769,9 @@ impl Conn { let mut buf = io::Cursor::new(ibuf); if self.compression_threshold >= 0 { + if self.compression_read.is_none() { + self.compression_read = Some(ZlibDecoder::new(io::Cursor::new(Vec::new()))); + } let uncompressed_size = try!(VarInt::read_from(&mut buf)).0; if uncompressed_size != 0 { let mut new = Vec::with_capacity(uncompressed_size as usize); @@ -806,13 +812,8 @@ impl Conn { self.cipher = Option::Some(openssl::EVPCipher::new(key, key, decrypt)); } - pub fn set_compresssion(&mut self, threshold: i32, read: bool) { + pub fn set_compresssion(&mut self, threshold: i32) { self.compression_threshold = threshold; - if read { - self.compression_read = Some(ZlibDecoder::new(io::Cursor::new(Vec::new()))); - } else { - self.compression_write = Some(ZlibEncoder::new(io::Cursor::new(Vec::new()), flate2::Compression::Default)); - } } pub fn do_status(mut self) -> Result<(Status, time::Duration), Error> {