From 1c1d53e17701ceff29e52b855a1e2f1a9577087a Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Thu, 21 Nov 2024 12:52:41 +1300 Subject: [PATCH] Add file access overload to RootStorage.Open --- OpenMcdf.Tests/RootStorageTests.cs | 1 + OpenMcdf/RootStorage.cs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/OpenMcdf.Tests/RootStorageTests.cs b/OpenMcdf.Tests/RootStorageTests.cs index a118a20..54600b4 100644 --- a/OpenMcdf.Tests/RootStorageTests.cs +++ b/OpenMcdf.Tests/RootStorageTests.cs @@ -12,6 +12,7 @@ public void Open(string fileName) using var rootStorage2 = RootStorage.OpenRead(fileName); Assert.ThrowsException(() => RootStorage.Open(fileName, FileMode.Open)); + Assert.ThrowsException(() => RootStorage.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); Assert.ThrowsException(() => RootStorage.OpenWrite(fileName)); } diff --git a/OpenMcdf/RootStorage.cs b/OpenMcdf/RootStorage.cs index 8c7dd5d..651a088 100644 --- a/OpenMcdf/RootStorage.cs +++ b/OpenMcdf/RootStorage.cs @@ -70,6 +70,14 @@ public static RootStorage Open(string fileName, FileMode mode, StorageModeFlags return Open(stream, flags); } + public static RootStorage Open(string fileName, FileMode mode, FileAccess access, StorageModeFlags flags = StorageModeFlags.None) + { + ThrowIfLeaveOpen(flags); + + FileStream stream = File.Open(fileName, mode, access); + return Open(stream, flags); + } + public static RootStorage Open(Stream stream, StorageModeFlags flags = StorageModeFlags.None) { stream.ThrowIfNotSeekable();