/// <summary> /// Compresses and resuses the ZLibStream's own BaseStream /// </summary> /// <param name="offset"></param> public static void WriteBasestream(this Joveler.Compression.ZLib.ZLibStream stream, long offset = 0) { stream.BaseStream.Position = 0; // the largest multiple of 4096 smaller than the LOH threshold byte[] buffer = ArrayPool <byte> .Shared.Rent(81920); // calculate the read position delta offset -= stream.TotalIn; // reading in chunks and jumping stream position is faster and allocates less with large streams int read; while ((read = stream.BaseStream.Read(buffer, 0, buffer.Length)) != 0) { // jump to the write position stream.BaseStream.Position = offset + stream.TotalOut; stream.Write(buffer, 0, read); // reset to the next read position stream.BaseStream.Position = offset + stream.TotalIn; } // jump to the final write position and flush the buffer stream.BaseStream.Position = offset + stream.TotalOut; stream.Flush(); ArrayPool <byte> .Shared.Return(buffer); }
public void ZLib() { Joveler.Compression.ZLib.ZLibCompressOptions compOpts = new Joveler.Compression.ZLib.ZLibCompressOptions() { BufferSize = BufferSize, }; Joveler.Compression.ZLib.ZLibDecompressOptions decompOpts = new Joveler.Compression.ZLib.ZLibDecompressOptions() { BufferSize = BufferSize, }; byte[] zlibData; using (MemoryStream ms = new MemoryStream()) { using (MemoryStream rms = new MemoryStream(_srcData)) using (Joveler.Compression.ZLib.ZLibStream xzs = new Joveler.Compression.ZLib.ZLibStream(ms, compOpts)) { rms.CopyTo(xzs); } zlibData = ms.ToArray(); } using (MemoryStream ms = new MemoryStream()) { using (MemoryStream rms = new MemoryStream(zlibData)) using (Joveler.Compression.ZLib.ZLibStream xzs = new Joveler.Compression.ZLib.ZLibStream(rms, decompOpts)) { xzs.CopyTo(ms); } } }
public double ZLib_Native() { long compLen; byte[] rawData = SrcFiles[SrcFileName]; using (MemoryStream ms = new MemoryStream()) { Joveler.Compression.ZLib.ZLibCompressOptions compOpts = new Joveler.Compression.ZLib.ZLibCompressOptions() { Level = NativeZLibLevelDict[Level], LeaveOpen = true, }; using (MemoryStream rms = new MemoryStream(rawData)) using (Joveler.Compression.ZLib.ZLibStream zs = new Joveler.Compression.ZLib.ZLibStream(ms, compOpts)) { rms.CopyTo(zs); } ms.Flush(); compLen = ms.Position; } CompRatio = (double)compLen / rawData.Length; return(CompRatio); }
public long ZLib_Native() { Joveler.Compression.ZLib.ZLibDecompressOptions decompOpts = new Joveler.Compression.ZLib.ZLibDecompressOptions(); byte[] compData = SrcFiles[$"{Level}_{SrcFileName}.zz"]; using MemoryStream ms = new MemoryStream(); using (MemoryStream rms = new MemoryStream(compData)) using (Joveler.Compression.ZLib.ZLibStream zs = new Joveler.Compression.ZLib.ZLibStream(rms, decompOpts)) { zs.CopyTo(ms); } ms.Flush(); return(ms.Length); }