Beispiel #1
0
        private byte[] GetDeflatedData(bool force = false)
        {
            if (!IsCompressed || force)
            {
                using (var dataStream = GetDataStream())
                {
                    return(Zlib.Compress(dataStream, GetDeflateLevel()));
                }
            }

            return(GetData());
        }
Beispiel #2
0
        private byte[] GetInflatedData(bool force = false)
        {
            if (IsCompressed || force)
            {
                using (var dataStream = GetDataStream())
                {
                    var decompressedData = Zlib.Decompress(dataStream, OriginalSize);

                    if (decompressedData.Length != OriginalSize)
                    {
                        throw new IOException("Inflated size did not match original size");
                    }

                    return(decompressedData);
                }
            }

            return(GetData());
        }
Beispiel #3
0
        public Stream GetContentStream(bool extract, bool force = false)
        {
            if (extract)
            {
                if (OriginalSize == 0)
                {
                    return(null);
                }

                if (IsCompressed || force)
                {
                    return(Zlib.DecompressStream(GetDataStream(), OriginalSize));
                }
            }
            else
            {
                if (!IsCompressed || force)
                {
                    return(Zlib.CompressStream(GetDataStream(), GetDeflateLevel()));
                }
            }

            return(GetDataStream());
        }