public CompressedChunk(XlBinaryReader Data) { this.CompressedChunkStart = Data.i; this.CompressedHeader = new CompressedChunkHeader(Data); this.CompressedData = new CompressedChunkData(this.CompressedHeader, Data); }
//protected TokenSequence _TokenSequence; public CompressedChunkData(CompressedChunkHeader header, XlBinaryReader Data) { this.header = header; if (header.CompressedChunkFlag == (Byte)0x00) { // page 57: CompressedChunkData contains an array of CompressedChunkHeader.CompressedChunkSize // elements plus 3 bytes of uncompressed data int ArraySize = header.CompressedChunkSize + 3; this.Data = new Byte[ArraySize]; int CopySize = header.CompressedChunkSize; // todo: this is my fix... Array.Copy(Data.ReadBytes(CopySize), 0, this.Data, 0, CopySize); //Array.Copy(Data, ArrayIndex, this.Data, 0, CopySize); //ArrayIndex += header.CompressedChunkSize; this.Decompress = (buffer, state) => DecompressRawChunk(buffer, state, this.Data); } else if (header.CompressedChunkFlag == (Byte)0x01) { // TODO: DO something like when compressedcurrent < compressedend -> add a new tokensequence // page 57: CompressedChunkData contains an array of TokenSequence elements var size = Math.Min(header.CompressedChunkSize, Data.Length - Data.i); var tokenSequences = new List <TokenSequence>(); int processedBytes = 0; while (processedBytes < size) { int remainingBytes = size - processedBytes; var tokenSequence = new TokenSequence(Data, remainingBytes); tokenSequences.Add(tokenSequence); processedBytes += tokenSequence.GetSizeInBytes(); } //var tokenSequenceBytes = tokenSequence.GetDataInRawBytes(); //this.Data = tokenSequenceBytes; //var tokenSequenceSize = tokenSequenceBytes.Count(); //if(tokenSequenceSize != header.CompressedChunkSize+3) //{ //throw new InvalidOperationException(String.Format("CompressedChunkData Data-array size expected {0}, but was {1}", header.CompressedChunkSize+3, tokenSequenceSize)); //} this.Decompress = (buffer, state) => DecompressTokenSequence(buffer, state, tokenSequences); } else { throw new Exception(); } //this._TokenSequence = new TokenSequence(ref Data); //Data = Data.Skip(N); }
protected ushort Header; // 2-byte / unsigned 16 bit public CompressedChunkHeader(XlBinaryReader Data) { // Algorithm as per page 60 var Header = Data.ReadUInt16(); Console.WriteLine("CompressionChunkHeader Data Bytes: {0} (uint16: {1})", Header.ToBitString(), Header); SetFrom(Header); Validate(); }
/// <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 CompressedContainer(XlBinaryReader CompressedData) { this.reader = CompressedData; this.CompressedRecordEnd = CompressedData.Length; // Read signature byte this.SignatureByte = CompressedData.ReadByte(); SanityCheckSignatureByte(this.SignatureByte); //while (ArrayIndex < CompressedRecordEnd) while (!CompressedData.EndOfData) { var chunk = new CompressedChunk(CompressedData); _Chunks.Add(chunk); } //throw new NotImplementedException(); }
public TokenSequence(XlBinaryReader CompressedData, int remainingBytes) { this.FlagByte = CompressedData.ReadByte(); --remainingBytes; for (int i = 0; i < 8; i++) { if (remainingBytes == 0) { break; } //int index = (i - 7) * (-1); // The most significant byte describes the first token. The second most significant byte the second token. etc. So we map 0 -> 7, 1 -> 6, 2 -> 5, 3 -> 4, 4 -> 3, 5 -> 2, 6 -> 1, 7 -> 0 TokenType tokenType = GetTokenTypeAtIndex(i); if (tokenType == TokenType.CopyToken) { var token = new CopyToken(CompressedData); this._Tokens.Add(token); remainingBytes -= token.GetSizeInBytes(); } else if (tokenType == TokenType.LiteralToken) { var token = new LiteralToken(CompressedData); this._Tokens.Add(token); remainingBytes -= token.GetSizeInBytes(); } else { throw new Exception(); } // todo: last token sequence could contain less than 8 tokens } }
public CopyToken(XlBinaryReader Data) { this.Token = Data.ReadUInt16(); }
public LiteralToken(XlBinaryReader Data) { this.Data = Data.ReadByte(); }