protected override Stream AddFileToBackingDirectoryOrDefault(string fileName) { if (Files.Any(f => f.Name == fileName)) { throw new ArgumentException("A file with the same name already exists."); } var newFile = new InMemoryVirtualFile(VirtualPathProvider, this) { FilePath = VirtualPathProvider.CombineVirtualPath(this.VirtualPath, fileName), FileName = fileName, ByteContents = new byte[0], }; var stream = new InMemoryStream((contents) => newFile.ByteContents = contents); this.files.Add(newFile); return(stream); }
public override Stream OpenWrite(WriteMode mode) { if (mode == WriteMode.Truncate) { return(new InMemoryStream((data) => { ByteContents = data; })); } else { var stream = new InMemoryStream((data) => { ByteContents = data; }, ByteContents ?? new byte[0]); if (mode == WriteMode.Append) { stream.Seek(stream.Length, SeekOrigin.Begin); } return(stream); } }
public override Stream OpenWrite(WriteMode mode) { if (mode == WriteMode.Truncate) { return new InMemoryStream((data) => { ByteContents = data; }); } else { var stream = new InMemoryStream((data) => { ByteContents = data; }, ByteContents ?? new byte[0]); if (mode == WriteMode.Append) { stream.Seek(stream.Length, SeekOrigin.Begin); } return stream; } }
protected override Stream AddFileToBackingDirectoryOrDefault(string fileName) { if (Files.Any(f => f.Name == fileName)) { throw new ArgumentException("A file with the same name already exists."); } var newFile = new InMemoryVirtualFile(VirtualPathProvider, this) { FilePath = VirtualPathProvider.CombineVirtualPath(this.VirtualPath, fileName), FileName = fileName, ByteContents = new byte[0], }; var stream = new InMemoryStream((contents) => newFile.ByteContents = contents); this.files.Add(newFile); return stream; }