示例#1
0
        // Section 2.4.1.3.6
        // page 62
        /// <summary>
        /// Compresses the data given in UncompressedData.
        /// </summary>
        /// <param name="UncompressedData">Uncompressed raw data</param>
        /// <returns>A byte array containing the compressed data</returns>
        public static Byte[] Compress(byte[] UncompressedData)
        {
            if (UncompressedData == null)
            {
                throw new ArgumentNullException("UncompressedData");
            }

            var resultBuffer = new CompressedBuffer(UncompressedData.Length);

            DecompressedBuffer uncompressedDataBuffer = new DecompressedBuffer(UncompressedData);
            var state = new DecompressionState(uncompressedDataBuffer);

            // 2.4.1.3.6 Compression algorithm
            resultBuffer.SetByte(state.CompressedCurrent, 0x01);
            ++state.CompressedCurrent;

            while (state.DecompressedCurrent < state.DecompressedBufferEnd)
            {
                state.CompressedChunkStart   = state.CompressedCurrent;
                state.DecompressedChunkStart = state.DecompressedCurrent;
                CompressDecompressedChunk(UncompressedData, resultBuffer, state);
            }

            return(resultBuffer.GetData());
        }
示例#2
0
 protected void DecompressTokenSequence(DecompressedBuffer buffer, DecompressionState state, IEnumerable <TokenSequence> tokenSequence)
 {
     foreach (var t in tokenSequence)
     {
         t.Decompress(buffer, state);
     }
 }
        public void Decompress(DecompressedBuffer buffer, DecompressionState state)
        {
            state.DecompressedChunkStart = state.DecompressedCurrent;
            //var CompressedEnd = Math.Min(state.CompressionRecordEnd, state.CompressedChunkStart + this.CompressedHeader.CompressedChunkSize);
            state.CompressedCurrent += 2;

            this.CompressedData.Decompress(buffer, state);
        }
        /*
         * public Byte[] GetDataInRawBytes()
         * {
         *  IEnumerable<Byte> result = new Byte[] { this.FlagByte };
         *  foreach(var token in _Tokens)
         *  {
         *      result = result.Concat(token.GetDataInRawBytes());
         *  }
         *
         *  return result.ToArray();
         * }*/

        public void Decompress(DecompressedBuffer buffer, DecompressionState state)
        {
            ++state.CompressedCurrent;

            foreach (var token in this._Tokens)
            {
                token.Decompress(buffer, state);
            }
        }
示例#5
0
 /// <summary>
 /// For compressing, where buffer is already filled with the fully decompressed data
 /// </summary>
 public DecompressionState(DecompressedBuffer buffer)
 {
     this.CompressionRecordEnd   = 0;                   // unknown yet
     this.CompressedCurrent      = 0;                   // to start with
     this.CompressedChunkStart   = 0;                   // to start with
     this.DecompressedCurrent    = 0;                   // to start with
     this.DecompressedBufferEnd  = buffer.Data.Count(); // todo: or +1?
     this.DecompressedChunkStart = 0;                   // to start with
 }
示例#6
0
        public override void Decompress(DecompressedBuffer buffer, DecompressionState state)
        {
            var decompressedChunk = new DecompressedChunk(new byte[] { Data });

            buffer.Add(decompressedChunk);

            ++state.DecompressedCurrent;
            ++state.CompressedCurrent;
        }
        public override void Decompress(DecompressedBuffer buffer, DecompressionState state)
        {
            var info = UnpackCopyToken(this.Token, state.DecompressedCurrent, state.DecompressedChunkStart);

            var copySource = state.DecompressedCurrent - info.Offset;

            // Call Byte Copy (section 2.4.1.3.11) with CopySource, DecompressedCurrent, and Length
            ByteCopy(buffer, copySource, state.DecompressedCurrent, info.Length);

            state.DecompressedCurrent += info.Length;
            state.CompressedCurrent   += 2;
        }
示例#8
0
        public void DecompressRawChunk(DecompressedBuffer buffer, DecompressionState state, Byte[] Data)
        {
            throw new NotImplementedException();

            Byte[] append = new Byte[4096];
            //Array.Copy(state.OriginalData, state.CompressedCurrent, append, 0, header.CompressedChunkSize);

            //int nCopy = Math.Min(4096, state.OriginalData.Length-state.CompressedCurrent);
            //Array.Copy(state.OriginalData, state.CompressedCurrent, append, 0, nCopy);
            Array.Copy(this.Data, 0, append, 0, 4096); // todo: maybe copy from original data?
            state.DecompressedCurrent += 4096;
            state.CompressedCurrent   += 4096;

            var x = new DecompressedChunk(append);

            buffer.Add(x);
        }
示例#9
0
        /// <summary>
        /// Decompresses the given data
        /// </summary>
        /// <param name="CompressedData">Byte array of the compressed data</param>
        /// <returns>A byte array containing the uncompressed data</returns>
        public static Byte[] Decompress(byte[] CompressedData)
        {
            if (CompressedData == null)
            {
                throw new ArgumentNullException("CompressedData");
            }

            var reader = new XlBinaryReader(ref CompressedData);

            reader.OutputAllAsBinary();
            var container = new CompressedContainer(reader);
            var buffer    = new DecompressedBuffer();

            container.Decompress(buffer);
            Byte[] UncompressedCompressedData = buffer.GetData();

            return(UncompressedCompressedData);
        }
        public void Decompress(DecompressedBuffer buffer)
        {
            var state = new DecompressionState();

            if (this.SignatureByte == (Byte)0x01)
            {
                ++state.CompressedCurrent;

                foreach (var chunk in _Chunks)
                {
                    state.CompressedChunkStart = state.CompressedCurrent;
                    chunk.Decompress(buffer, state);
                }
            }
            else
            {
                throw new FormatException("Signature byte was not 0x01");
            }
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="OriginalData"></param>
        /// <param name="CopySource">Specifies the location, in the DecompressedBuffer, of the first byte of the source sequence</param>
        /// <param name="DestinationSource">Specifies the location, in the DecompressedBuffer, of the first byte of the destination sequence</param>
        /// <param name="ByteCount">Specifies the number of bytes to copy. MUST be greater than 0.</param>
        protected void ByteCopy(DecompressedBuffer buffer, int CopySource, int DestinationSource, int ByteCount)
        {
            if (ByteCount <= 0)
            {
                throw new ArgumentOutOfRangeException("ByteCount", ByteCount, "ByteCount must be greater than 0");
            }

            var SrcCurrent = CopySource;
            var DstCurrent = DestinationSource;

            for (int i = 1; i <= ByteCount; i++)
            {
                var byteToCopy = buffer.GetByteAt(SrcCurrent);
                //var byteToCopy = OriginalData.ReadByteAt(SrcCurrent);
                buffer.SetByte(DstCurrent, byteToCopy);
                ++SrcCurrent;
                ++DstCurrent;
            }
        }
 public abstract void Decompress(DecompressedBuffer buffer, DecompressionState state);
示例#13
0
 public static void Decompress(DecompressedBuffer outputBuffer, CompressedContainer container)
 {
 }