/// <summary> /// Read bytes in input/output buffer from the current position /// </summary> /// <param name="count">The maximum number of bytes to read.</param> /// <param name="bufferType">Read in input or output buffer.</param> /// <returns>Contains the specified byte array.</returns> public static byte[] ReadBytes(int count, ZLibBufferType bufferType) { uint newPosition; uint bufferSize; if (bufferType == ZLibBufferType.OutputBuffer) { newPosition = (uint)(OutputBufferPosition + count); bufferSize = OutputBufferLength; } else { newPosition = (uint)(InputBufferPosition + count); bufferSize = InputBufferLength; } if (newPosition > bufferSize) { string msg = "ZLibWrapper.ReadBytes: " + string.Format(format: TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLibWrapper_FinalPositionOverBufferSize2"), arg0: newPosition.ToString(CultureInfo.InvariantCulture), arg1: bufferType.ToString(), arg2: bufferSize.ToString(CultureInfo.InvariantCulture)); Clipboard.SetText(msg); throw new TESParserException(msg); } var b = new byte[count]; if (bufferType == ZLibBufferType.OutputBuffer) { Array.Copy(_outputBuffer, OutputBufferPosition, b, 0, count); OutputBufferPosition += (uint)count; } else { Array.Copy(_inputBuffer, InputBufferPosition, b, 0, count); InputBufferPosition += (uint)count; } return b; }
/// <summary> /// Set position in input/output buffer /// </summary> /// <param name="position">New position in buffer</param> /// <param name="bufferType">Buffer type (input or output)</param> public static void Position(uint position, ZLibBufferType bufferType) { uint bufferSize = bufferType == ZLibBufferType.OutputBuffer ? OutputBufferLength : InputBufferLength; if (position > bufferSize) { string msg = string.Format( "ZLibWrapper.Position: " + string.Format(format: TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLibWrapper_PositionOverBufferSize"), arg0: bufferSize.ToString(CultureInfo.InvariantCulture))); Clipboard.SetText(msg); throw new TESParserException(msg); } if (bufferType == ZLibBufferType.OutputBuffer) OutputBufferPosition = position; else InputBufferPosition = position; }