/// <summary> /// Initializes a new instance of the <see cref="DataStream"/> class. /// </summary> /// <param name="filePath">File path.</param> /// <param name="mode">File open mode.</param> /// <param name="offset">Offset from the start of the file.</param> /// <param name="length">Length of this DataStream.</param> public DataStream(string filePath, FileOpenMode mode, long offset, long length) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException(nameof(filePath)); } long fileSize = new FileInfo(filePath).Length; if (offset < 0 || offset > fileSize) { throw new ArgumentOutOfRangeException(nameof(offset)); } if (length < 0 || offset + length > fileSize) { throw new ArgumentOutOfRangeException(nameof(length)); } BaseStream = new FileStream(filePath, mode.ToFileMode(), mode.ToFileAccess()); isSubstream = true; Offset = offset; this.length = length; IncreaseStreamCounter(BaseStream); }
/// <summary> /// Initializes a new instance of the <see cref="DataStream"/> class. /// </summary> /// <param name="filePath">File path.</param> /// <param name="mode">File open mode.</param> public DataStream(string filePath, FileOpenMode mode) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException(nameof(filePath)); } BaseStream = new FileStream(filePath, mode.ToFileMode(), mode.ToFileAccess()); Offset = 0; Length = BaseStream.Length; IncreaseStreamCounter(BaseStream); }
void Initialize() { isInitialized = true; BaseStream = new FileStream(path, mode.ToFileMode(), mode.ToFileAccess()); }