private void WriteBlock(byte[] writeBuff, ref ushort engaged, ref int uncompressedSize) { uncompressedSize += engaged; byte[] encoding = ZtrFileEncoding.CompressZtrContent(writeBuff, 0, ref engaged); _output.Write(encoding, 0, encoding.Length); _output.Write(writeBuff, 0, engaged); engaged = 0; }
public void Unpack(int compressedSize) { if (compressedSize < 1) { return; } int index = 0, blockNumber = 0; using (MemoryStream io = new MemoryStream(32768)) { byte[] readBuff = new byte[4096]; while (compressedSize > 0) { int offset = 0; ZtrFileEncoding tagsEncoding = ZtrFileEncoding.ReadFromStream(_input); compressedSize = compressedSize - tagsEncoding.BlockSize - 4; long blockOffset = _input.Position; while (offset < 4096 && compressedSize > 0) { while (index < _offsets.Length && _offsets[index].Block == blockNumber && _input.Position - blockOffset == _offsets[index].PackedOffset) { _offsets[index].UnpackedOffset = (int)(io.Position + offset + _offsets[index].BlockOffset); if (index > 0) { _offsets[index - 1].UnpackedLength = _offsets[index].UnpackedOffset - _offsets[index - 1].UnpackedOffset; } index++; } int value = _input.ReadByte(); byte[] replace = tagsEncoding.Encoding[value]; Array.Copy(replace, 0, readBuff, offset, replace.Length); offset += replace.Length; compressedSize--; } io.Write(readBuff, 0, offset); blockNumber++; } _offsets[index - 1].UnpackedLength = (int)(io.Position - _offsets[index - 1].UnpackedOffset); for (int i = 0; i < _offsets.Length; i++) { io.SetPosition(_offsets[i].UnpackedOffset); byte[] buff = io.EnsureRead(_offsets[i].UnpackedLength); _output[i].Value = _encoding.GetString(buff, 0, buff.Length - 2); } } }
private void WriteBlock(byte[] writeBuff, ref ushort engaged, ushort[,] innerOffsets, List <int> blockOffsets) { byte[] encoding = ZtrFileEncoding.FakeCompression(writeBuff, 0, ref engaged, innerOffsets, _innerIndex, _innerCount); _output.Write(encoding, 0, encoding.Length); _output.Write(writeBuff, 0, engaged); _blockOffset += encoding.Length; _blockOffset += engaged; _blockNumber = checked ((byte)(_blockNumber + 1)); _innerIndex += _innerCount; _innerCount = 0; blockOffsets.Add(_blockOffset); engaged = 0; }
public void Unpack(int uncompressedSize) { int index = 0, lastOffset = 0; byte[] readBuff = new byte[Math.Min(uncompressedSize, 4096)]; byte[] codeBuff = new byte[readBuff.Length * 2]; while (uncompressedSize > 0) { int offset = 0; ZtrFileEncoding tagsEncoding = ZtrFileEncoding.ReadFromStream(_input); while (offset < 4096 && uncompressedSize > 0) { int value = _input.ReadByte(); byte[] replace = tagsEncoding.Encoding[value]; Array.Copy(replace, 0, readBuff, offset, replace.Length); offset += replace.Length; uncompressedSize -= replace.Length; } // Выбираем полные строки Array.Copy(readBuff, 0, codeBuff, lastOffset, offset); int initial = 0, length = offset + lastOffset; for (int i = lastOffset; i < length; i++) { if (codeBuff[i] == 0) { _output[index++].Key = Encoding.ASCII.GetString(codeBuff, initial, i - initial); initial = i + 1; } } if (initial == 0) { throw new NotImplementedException(); } lastOffset = length - initial; Array.Copy(codeBuff, initial, codeBuff, 0, lastOffset); } }