/// <summary> /// Opens the file using the specified options. /// </summary> /// <param name="fileMode">The file mode.</param> /// <param name="fileAccess">The file access.</param> /// <param name="fileShare">The file share.</param> /// <returns>A <see cref="Stream" /> to the file.</returns> public Stream Open(FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { bool fileWasCreated; var position = GetPosition(fileMode, out fileWasCreated); if (fileWasCreated) { _tree.CreateFile(this); } return(new FakeFileStream(this) { Position = position }); }
private long GetPosition(FileMode fileMode, out bool fileWasCreated) { fileWasCreated = false; if (Exists) { switch (fileMode) { case FileMode.CreateNew: throw new IOException(); case FileMode.Create: case FileMode.Truncate: Length = 0; return(0); case FileMode.Open: case FileMode.OpenOrCreate: return(0); case FileMode.Append: return(Length); } } else { switch (fileMode) { case FileMode.Create: case FileMode.Append: case FileMode.CreateNew: case FileMode.OpenOrCreate: fileWasCreated = true; Exists = true; return(Length); case FileMode.Open: case FileMode.Truncate: throw new FileNotFoundException(); } } throw new NotSupportedException(); }
public Stream Open(FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { return(_file.Open((System.IO.FileMode)fileMode, (System.IO.FileAccess)fileAccess, (System.IO.FileShare)fileShare)); }