diff --git a/Cargo.toml b/Cargo.toml index be2c556e5ea870824520a9cdf58c5b2c6ec50c45..ddb0fdbbf3fd81d343647e65decb8eb78df74c86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ path = "examples/main.rs" base64 = "0.10" xml-rs = "0.8" libflate = "0.1.18" +zstd = "0.5" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index cd201360dd4eddcb5dd8791913fbd5682f1e197c..7b3254ecfa18870ff64b4163445749634fd3e73c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1044,6 +1044,11 @@ fn parse_data<R: Read>( .and_then(decode_gzip) .map(|v| convert_to_tile(&v, width)) } + ("base64", "zstd") => { + return parse_base64(parser) + .and_then(decode_zstd) + .map(|v| convert_to_tile(&v, width)) + } (e, c) => { return Err(TiledError::Other(format!( "Unknown combination of {} encoding and {} compression", @@ -1094,6 +1099,19 @@ fn decode_gzip(data: Vec<u8>) -> Result<Vec<u8>, TiledError> { Ok(data) } +fn decode_zstd(data: Vec<u8>) -> Result<Vec<u8>, TiledError> { + use std::io::Cursor; + use zstd::stream::read::Decoder; + + let buff = Cursor::new(&data); + let mut zd = Decoder::with_buffer(buff).map_err(|e| TiledError::DecompressingError(e))?; + + let mut data = Vec::new(); + zd.read_to_end(&mut data) + .map_err(|e| TiledError::DecompressingError(e))?; + Ok(data) +} + fn decode_csv<R: Read>(parser: &mut EventReader<R>) -> Result<Vec<Vec<LayerTile>>, TiledError> { loop { match parser.next().map_err(TiledError::XmlDecodingError)? {