Skip to content
Snippets Groups Projects
Commit 32cff6f5 authored by tatref's avatar tatref
Browse files

add support for base64/zstd

parent 688dcf9d
No related branches found
No related tags found
No related merge requests found
...@@ -24,3 +24,4 @@ path = "examples/main.rs" ...@@ -24,3 +24,4 @@ path = "examples/main.rs"
base64 = "0.10" base64 = "0.10"
xml-rs = "0.8" xml-rs = "0.8"
libflate = "0.1.18" libflate = "0.1.18"
zstd = "0.5"
\ No newline at end of file
...@@ -1044,6 +1044,11 @@ fn parse_data<R: Read>( ...@@ -1044,6 +1044,11 @@ fn parse_data<R: Read>(
.and_then(decode_gzip) .and_then(decode_gzip)
.map(|v| convert_to_tile(&v, width)) .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) => { (e, c) => {
return Err(TiledError::Other(format!( return Err(TiledError::Other(format!(
"Unknown combination of {} encoding and {} compression", "Unknown combination of {} encoding and {} compression",
...@@ -1094,6 +1099,19 @@ fn decode_gzip(data: Vec<u8>) -> Result<Vec<u8>, TiledError> { ...@@ -1094,6 +1099,19 @@ fn decode_gzip(data: Vec<u8>) -> Result<Vec<u8>, TiledError> {
Ok(data) 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> { fn decode_csv<R: Read>(parser: &mut EventReader<R>) -> Result<Vec<Vec<LayerTile>>, TiledError> {
loop { loop {
match parser.next().map_err(TiledError::XmlDecodingError)? { match parser.next().map_err(TiledError::XmlDecodingError)? {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment