Skip to content

Commit

Permalink
Removal of DotNetZip; explicit zlib deflate
Browse files Browse the repository at this point in the history
This patch removes the `zlib` source from TiledSharp and relies on
intrinsic .NET libraries to decompress gzip and Zlib streams.  Since
.NET does not have explicit Zlib support, we manually strip the header
and footer, and use the `DeflateStream` on the body.
  • Loading branch information
marshallward committed Oct 27, 2016
1 parent 4be2032 commit b4f9599
Show file tree
Hide file tree
Showing 17 changed files with 15 additions and 11,366 deletions.
13 changes: 0 additions & 13 deletions TiledSharp/TiledSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@
<Compile Include="src\Layer.cs" />
<Compile Include="src\Tileset.cs" />
<Compile Include="src\AssemblyInfo.cs" />
<Compile Include="src\zlib\CRC32.cs" />
<Compile Include="src\zlib\Deflate.cs" />
<Compile Include="src\zlib\DeflateStream.cs" />
<Compile Include="src\zlib\GZipStream.cs" />
<Compile Include="src\zlib\InfTree.cs" />
<Compile Include="src\zlib\Inflate.cs" />
<Compile Include="src\zlib\ParallelDeflateOutputStream.cs" />
<Compile Include="src\zlib\Tree.cs" />
<Compile Include="src\zlib\Zlib.cs" />
<Compile Include="src\zlib\ZlibBaseStream.cs" />
<Compile Include="src\zlib\ZlibCodec.cs" />
<Compile Include="src\zlib\ZlibConstants.cs" />
<Compile Include="src\zlib\ZlibStream.cs" />
<Compile Include="src\ObjectGroup.cs" />
<Compile Include="src\ImageLayer.cs" />
</ItemGroup>
Expand Down
21 changes: 15 additions & 6 deletions TiledSharp/src/TiledCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,21 @@ public TmxBase64Data(XElement xData)
Data = new MemoryStream(rawData, false);

var compression = (string)xData.Attribute("compression");
if (compression == "gzip")
Data = new Ionic.Zlib.GZipStream(Data,
Ionic.Zlib.CompressionMode.Decompress, false);
else if (compression == "zlib")
Data = new Ionic.Zlib.ZlibStream(Data,
Ionic.Zlib.CompressionMode.Decompress, false);
if (compression == "gzip") {
Data = new GZipStream (Data, CompressionMode.Decompress);
}
else if (compression == "zlib") {
// Strip 2-byte header and 4-byte checksum
// TODO: Validate header here
var bodyLength = rawData.Length - 6;
byte[] bodyData = new byte[bodyLength];
Array.Copy (rawData, 2, bodyData, 0, bodyLength);

This comment has been minimized.

Copy link
@bjorn

bjorn Dec 8, 2016

Contributor

Rather than copying the data, you could probably use this MemoryStream constructor that takes an index and count for specifying the region of the byte array.

This comment has been minimized.

Copy link
@marshallward

marshallward Dec 9, 2016

Author Owner

Will that work here? Can streams be used in place of byte arrays?
I agree the section is a bit borked at the moment (#41) and those streams need to be cleaned up.

This comment has been minimized.

Copy link
@bjorn

bjorn Dec 9, 2016

Contributor

I haven't tested it, but looking at the API of MemoryStream the following should work the same way:

var bodyStream = new MemoryStream (rawData, 2, bodyLength, false);

That way, you don't need the bodyData copy.


var bodyStream = new MemoryStream (bodyData, false);
Data = new DeflateStream (bodyStream, CompressionMode.Decompress);

// TODO: Validate checksum?
}
else if (compression != null)
throw new Exception("TmxBase64Data: Unknown compression.");
}
Expand Down
Loading

0 comments on commit b4f9599

Please sign in to comment.