Exemplo n.º 1
0
        /// <summary>
        /// Decompressed a block of data. It is assumed that this data is compressed with one
        /// or more algorithms, and that it is prepended by a single byte describing the algorithms
        /// used. See <see cref="CompressionAlgorithms"/> for valid algorithms.
        /// </summary>
        /// <param name="pendingSector">The compressed data.</param>
        /// <returns>The decompressed data.</returns>
        public static byte[] DecompressData(byte[] pendingSector)
        {
            // The sector is compressed using a combination of techniques.
            // Examine the first byte to determine the compression algorithms used
            CompressionAlgorithms compressionAlgorithms = (CompressionAlgorithms)pendingSector[0];

            // Drop the first byte
            byte[] sectorData = new byte[pendingSector.Length - 1];
            Buffer.BlockCopy(pendingSector, 1, sectorData, 0, sectorData.Length);
            pendingSector = sectorData;

            // Walk through each compression algorithm in reverse order
            if (compressionAlgorithms.HasFlag(CompressionAlgorithms.BZip2))
            {
                // Decompress sector using BZIP2
                pendingSector = DecompressBZip2(pendingSector);
            }

            if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Implode))
            {
                // Decompress sector using PKWARE Implode
                pendingSector = DecompressPKWAREImplode(pendingSector);
            }

            if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Deflate))
            {
                // Decompress sector using Deflate
                pendingSector = DecompressDeflate(pendingSector);
            }

            if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Huffman))
            {
                // Decompress sector using Huffman
                pendingSector = DecompressHuffman(pendingSector);
            }

            if (compressionAlgorithms.HasFlag(CompressionAlgorithms.ADPCMStereo))
            {
                // Decompress sector using ADPCM Stereo
                pendingSector = DecompressADPCMStereo(pendingSector);
            }

            if (compressionAlgorithms.HasFlag(CompressionAlgorithms.ADPCMMono))
            {
                // Decompress sector using ADPCM Mono
                pendingSector = DecompressADPCMMono(pendingSector);
            }

            if (compressionAlgorithms.HasFlag(CompressionAlgorithms.Sparse))
            {
                // Decompress sector using Sparse
                pendingSector = DecompressSparse(pendingSector);
            }

            return(pendingSector);
        }