public void Compress(string inputFile, string outputFile) { FileInfo file = new FileInfo(inputFile); buffer = new byte[file.Length]; int index = 0; using (BitReader bitReader = new BitReader(inputFile)) using (BitWriter bitWriter = new BitWriter(outputFile)) { FillBuffer(bitReader); int character = buffer[index]; int position = 0; int length = 0; //first token WriteToken(bitWriter, position, length, character); _slidingWindow.Add(character); index++; character = buffer[index]; length = 0; while (index < buffer.Length) { int i = 0; string prevChar = null; while (i < _searchBufferMaxLength) { if (i < _slidingWindow.Count) { break; } int lookAheadIndex = index - i - 1; if (buffer[lookAheadIndex] == character) { //vezi cat de lunga ii secventa de potrivire prevChar = character.ToString(); int j = lookAheadIndex; while (j < _lookAheadBufferMaxLength + i) { if (j > buffer.Length) { break; } character = buffer[lookAheadIndex]; } } else { i++; } } } /*******************************************************************************/ //first token WriteToken(bitWriter, position, length, character); _slidingWindow.Add(character); character = bitReader.readNBits(8); position = 0; if (_slidingWindow[0] == character) { length = 1; _slidingWindow.Add(character); character = bitReader.readNBits(8); } else { length = 0; } //second token WriteToken(bitWriter, position, length, character); _slidingWindow.Add(character); character = bitReader.readNBits(8); if (_slidingWindow[1] == character) { position = 0; _slidingWindow.Add(character); character = bitReader.readNBits(8); if (_slidingWindow[2] == character) { } else { } } else if (_slidingWindow[0] == character) { position = 1; _slidingWindow.Add(character); character = bitReader.readNBits(8); if (_slidingWindow[1] == character) { } else { length = 1; } } //third token WriteToken(bitWriter, position, length, character); } }