From 32cff6f5288336525f7db612e693c2996779a8c6 Mon Sep 17 00:00:00 2001
From: tatref <tatref@github.com>
Date: Sat, 16 May 2020 01:26:27 +0200
Subject: [PATCH] add support for base64/zstd

---
 Cargo.toml |  1 +
 src/lib.rs | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/Cargo.toml b/Cargo.toml
index be2c556..ddb0fdb 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 cd20136..7b3254e 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)? {
-- 
GitLab