public BitArrayWrapper Read2ndOrderCodeWord(BitInputStream input) { bool done = false; int prevbit = 0; int curbit = 0; int bcounter = -1; BitArrayWrapper tempSet = new BitArrayWrapper(); while (done == false) { curbit = input.ReadBit(); bcounter++; if ((curbit == 1) & (prevbit == 1)) { done = true; } else if ((curbit == 1) & (prevbit == 0)) { tempSet.Set(bcounter); prevbit = curbit; } else { prevbit = curbit; } } return(tempSet); }
public void Decompress(BitInputStream input, Stream output, long bufferSize) { long pairLength = -1000; long pairPosition = -1000; long currentBufferPosition = 0; long fileSize; long adj = 0; BitArray tempArray = new BitArray(1); fileSize = Decode3rdOrderCodeWord(Read3rdOrderCodeWord(input)); bufferSize = Decode3rdOrderCodeWord(Read3rdOrderCodeWord(input)); byte[] buffer = new byte[fileSize]; while (currentBufferPosition < fileSize) { if (fileSize != bufferSize) { adj = currentBufferPosition; } pairLength = Decode2ndOrderCodeWord(Read2ndOrderCodeWord(input)); pairPosition = Decode3rdOrderCodeWord(Read3rdOrderCodeWord(input)); if ((pairLength > -1) & (pairPosition > -1)) { if (pairLength == 0) { buffer[currentBufferPosition] = (byte)pairPosition; currentBufferPosition++; } else { for (long i = 0; i < pairLength; i++) { buffer[currentBufferPosition + i] = buffer[adj + pairPosition + i - 1]; } currentBufferPosition += pairLength; } } } WriteDecoding(output, buffer); }
private static void DecompressFile(string inputFileName, string outputFileName) { var timeSpan = TimedAction(() => { OracleDecoder _decoder = new OracleDecoder(); using (var inputStream = new FileStream(inputFileName, FileMode.Open)) { using (var outputStream = new FileStream(outputFileName, FileMode.CreateNew)) { using (var bitInputStream = new BitInputStream(inputStream)) { _decoder.Decompress(bitInputStream, outputStream, BufferSize); } } } }); Console.WriteLine("Decompression Time : {0}", timeSpan.ToString("g")); }