Skip to content

Commit 32f8963

Browse files
committed
Load paths via memory-mapped file
1 parent 6111d21 commit 32f8963

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

TotalImage.IO/Containers/Container.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.IO.MemoryMappedFiles;
34
using System.Text;
45
using 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

0 commit comments

Comments
 (0)