Example #1
0
        private void LoadRun(CompressedRun run)
        {
            int toCopy = (int)(run.SectorCount * Sizes.Sector);

            switch (run.Type)
            {
            case RunType.ZlibCompressed:
                _stream.Position = run.CompOffset + 2;     // 2 byte zlib header
                using (DeflateStream ds = new DeflateStream(_stream, CompressionMode.Decompress, true))
                {
                    Utilities.ReadFully(ds, _decompBuffer, 0, toCopy);
                }

                break;

            case RunType.AdcCompressed:
                _stream.Position = run.CompOffset;
                byte[] compressed = Utilities.ReadFully(_stream, (int)run.CompLength);
                if (ADCDecompress(compressed, 0, compressed.Length, _decompBuffer, 0) != toCopy)
                {
                    throw new InvalidDataException("Run too short when decompressed");
                }

                break;

            case RunType.BZlibCompressed:
                using (BZip2DecoderStream ds = new BZip2DecoderStream(new SubStream(_stream, run.CompOffset, run.CompLength), Ownership.None))
                {
                    Utilities.ReadFully(ds, _decompBuffer, 0, toCopy);
                }

                break;

            case RunType.Zeros:
            case RunType.Raw:
                break;

            default:
                throw new NotImplementedException("Unrecognized run type " + run.Type);
            }

            _activeRun = run;
        }
Example #2
0
        private void LoadRun(CompressedRun run)
        {
            int toCopy = (int)(run.SectorCount * Sizes.Sector);

            switch (run.Type)
            {
                case RunType.ZlibCompressed:
                    _stream.Position = run.CompOffset + 2; // 2 byte zlib header
                    using (DeflateStream ds = new DeflateStream(_stream, CompressionMode.Decompress, true))
                    {
                        Utilities.ReadFully(ds, _decompBuffer, 0, toCopy);
                    }

                    break;

                case RunType.AdcCompressed:
                    _stream.Position = run.CompOffset;
                    byte[] compressed = Utilities.ReadFully(_stream, (int)run.CompLength);
                    if (ADCDecompress(compressed, 0, compressed.Length, _decompBuffer, 0) != toCopy)
                    {
                        throw new InvalidDataException("Run too short when decompressed");
                    }

                    break;

                case RunType.BZlibCompressed:
                    using (BZip2DecoderStream ds = new BZip2DecoderStream(new SubStream(_stream, run.CompOffset, run.CompLength), Ownership.None))
                    {
                        Utilities.ReadFully(ds, _decompBuffer, 0, toCopy);
                    }

                    break;

                case RunType.Zeros:
                case RunType.Raw:
                    break;

                default:
                    throw new NotImplementedException("Unrecognized run type " + run.Type);
            }

            _activeRun = run;
        }