public static void Decompress(string bz2File, string localFile, string type)
 {
     using (var fs = new FileStream(bz2File, FileMode.Open, FileAccess.Read))
         using (var fsOut = File.Create(localFile))
         {
             if (type == "bzip2")
             {
                 BZip2Decompressor.Decompress(fs, fsOut, true);
             }
             else if (type == "gzip")
             {
                 using (var GZipDecompressor = new GZipStream(fs, CompressionMode.Decompress))
                 {
                     GZipDecompressor.CopyTo(fsOut);
                 }
             }
         }
 }
Exemple #2
0
        private void decompress(byte[] data)
        {
            DataInputStream stream = new DataInputStream(data);

            if (_keys != null && _keys.Length != 0)
            {
                stream.decodeXTEA(_keys);
            }

            int compression = stream.readUnsignedByte();

            _compression = (CompressionType)(compression > 2 ? 2 : compression);

            int compressedLength = stream.readInt();

            if (compressedLength < 0 || compressedLength > 1000000)
            {
                throw new InvalidOperationException("INVALID ARCHIVE HEADER");
            }

            int length;

            switch (_compression)
            {
            case CompressionType.RAW:
                _data = new byte[compressedLength];
                checkRevision(stream, compressedLength);

                stream.Read(_data, 0, compressedLength);
                break;

            case CompressionType.BZIP:
                length = stream.readInt();

                if (length <= 0)
                {
                    _data = null;
                }
                else
                {
                    _data = new byte[length];
                    checkRevision(stream, compressedLength);
                    BZip2Decompressor.Decompress(_data, data);
                }
                break;

            default:                     // GZIP
                length = stream.readInt();

                if (length <= 0 || length > 1000000000)
                {
                    _data = null;
                }
                else
                {
                    _data = new byte[length];
                    checkRevision(stream, compressedLength);
                    GZipDecompressor.Decompress(_data, stream);
                }
                break;
            }
        }