File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . IO ;
3+ using System . IO . MemoryMappedFiles ;
34using System . Text ;
45using TotalImage . Partitions ;
56
@@ -10,6 +11,11 @@ namespace TotalImage.Containers
1011 /// </summary>
1112 public abstract class Container : IDisposable
1213 {
14+ /// <summary>
15+ /// The backing file containing the image, opened as a memory-mapped file
16+ /// </summary>
17+ protected readonly MemoryMappedFile ? backingFile ;
18+
1319 /// <summary>
1420 /// The underlying stream containing the image
1521 /// </summary>
@@ -51,7 +57,8 @@ public PartitionTable PartitionTable
5157 /// <param name="path">The location of the image file</param>
5258 protected Container ( string path )
5359 {
54- containerStream = new FileStream ( path , FileMode . Open , FileAccess . Read , FileShare . Read ) ;
60+ backingFile = MemoryMappedFile . CreateFromFile ( path , FileMode . Open ) ;
61+ containerStream = backingFile . CreateViewStream ( 0 , 0 , MemoryMappedFileAccess . Read ) ;
5562 }
5663
5764 /// <summary>
@@ -132,6 +139,7 @@ protected virtual void Dispose(bool disposing)
132139 if ( disposing )
133140 {
134141 containerStream . Dispose ( ) ;
142+ backingFile ? . Dispose ( ) ;
135143 }
136144 }
137145
You can’t perform that action at this time.
0 commit comments