imaginary-hero-designer icon indicating copy to clipboard operation
imaginary-hero-designer copied to clipboard

consider switching out zlib for SharpZipLib

Open patrickhuber opened this issue 6 years ago • 0 comments

The dependency on zlib uses a c library which lacks a managed interface and regular updates that can be achieved with a nuget package of SharpZipLib.

I implemented a proof of concept decoding the hex codes of www.cityofheroesplanner.com in my data export library here:

  • Compression Tests: https://github.com/patrickhuber/city-of-info/blob/master/src/CityOfInfo.Data.Mids.Tests/CompressionDataStreamTests.cs
  • Hex Conversion Tests: https://github.com/patrickhuber/city-of-info/blob/master/src/CityOfInfo.Data.Mids.Tests/HexUtilTests.cs (the current mids code for this does a lot of string conversion which isn't as efficient as doing byte code scans)

Code under test here:

  • https://github.com/patrickhuber/city-of-info/blob/master/src/CityOfInfo.Data.Mids/CompressionDataStream.cs
  • https://github.com/patrickhuber/city-of-info/blob/master/src/CityOfInfo.Data.Mids/CompressionData.cs
  • https://github.com/patrickhuber/city-of-info/blob/master/src/CityOfInfo.Data.Mids/HexUtil.cs

Its pretty simple to get it setup:

install SharpZipLib

install-package SharpZipLib

Create a stream around an existing byte stream (like the hex stream from the encoded build urls)

var encoded = Encoding.ASCII.GetBytes(data.EncodedString);
var decodedBytes = HexUtil.Decode(encoded);
var compressedStream = new MemoryStream(decodedBytes);
_internalStream = new InflaterInputStream(compressedStream);

Read from the internal stream like you would any other stream. For example, wrapping it in a BinaryReader. I happened to encapsulate it in a wrapper class so I could avoid the boiler plate code for setting it up.

patrickhuber avatar Aug 30 '19 17:08 patrickhuber