/// <summary> /// Read bytes in file stream from the current position /// </summary> /// <param name="count">The maximum number of bytes to read.</param> /// <returns>Contains the specified byte array.</returns> public byte[] ReadBytes(int count) { var b = new byte[count]; SnipStream.Read(b, 0, count); return(b); }
/// <summary> /// Write UInt32 in file stream /// </summary> /// <param name="value">A UInt32 value.</param> public void WriteUInt32(UInt32 value) { if (SnipStream != null) { _bytes4 = Framework.TypeConverter.i2h(value); SnipStream.Write(_bytes4, 0, _bytes4.Length); } }
/// <summary> /// Writes an array of bytes in the file stream /// </summary> /// <param name="b">A byte array.</param> public void WriteBytesArrayInFileStream(byte[] b) { if (SnipStream == null) { return; } SnipStream.Write(b, 0, b.Length); }
/// <summary> /// Close the file stream /// </summary> public void CloseAndDisposeFileStream() { if (SnipStream != null) { SnipStream.Close(); SnipStream.Dispose(); } SnipStream = null; }
/// <summary> /// Writes the output buffer in the file stream /// </summary> public void WriteOutputBufferInFileStream() { if (SnipStream == null) { return; } if (OutputBufferLength <= 0) { return; } SnipStream.Write(OutputBuffer, 0, (int)OutputBufferLength); }
/// <summary> /// Writes a string in the file stream /// </summary> /// <param name="s">String to write</param> public void WriteStringInFileStream(string s) { if (SnipStream == null) { return; } if (string.IsNullOrWhiteSpace(s)) { return; } var b = new byte[s.Length]; for (int i = 0; i < s.Length; i++) { b[i] = (byte)s[i]; } SnipStream.Write(b, 0, s.Length); }
/// <summary> /// Jump to position in stream from offset /// </summary> /// <param name="offset">Offset (can be negative or positive)</param> /// <param name="from">Reference points in stream</param> /// <exception cref="Exception">An exception if size or position error</exception> public void JumpTo(int offset, SeekOrigin from) { if (SnipStream != null) { long newPosition = SnipStream.Position; if (@from == SeekOrigin.Begin) { newPosition = offset; } if (@from == SeekOrigin.Current) { newPosition += offset; } if (@from == SeekOrigin.End) { newPosition += offset; } if (newPosition > _streamSize) { throw new Exception( string.Format( format: TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "SnipStreamWrapper_JumpTo_GreaterSize"), arg0: newPosition.ToString(CultureInfo.InvariantCulture), arg1: _streamSize.ToString(CultureInfo.InvariantCulture))); } if (newPosition < 0) { throw new Exception( string.Format( format: TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "SnipStreamWrapper_JumpTo_PositionNegative"), arg0: newPosition.ToString(CultureInfo.InvariantCulture))); } SnipStream.Seek(offset, from); } }
/// <summary> /// Read UInt32 in file stream from the current position /// </summary> /// <returns>An UInt32 number</returns> public UInt32 ReadUInt32() { SnipStream.Read(_bytes4, 0, 4); return(BitConverter.ToUInt32(_bytes4, 0)); }
/// <summary> /// Read UInt16 in file stream from the current position /// </summary> /// <returns>An UInt16 number</returns> public UInt16 ReadUInt16() { SnipStream.Read(_bytes2, 0, 2); return(BitConverter.ToUInt16(_bytes2, 0)); }