File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
+ using System . IO . MemoryMappedFiles ;
4
5
using System . Linq ;
6
+ using System . Security ;
5
7
using System . Text ;
6
8
using System . Threading . Tasks ;
7
9
using Microsoft . Extensions . Logging ;
@@ -189,9 +191,28 @@ private void PreProcess()
189
191
fileProcessor . PreProcess ( ) ;
190
192
}
191
193
194
+ private Stream GetFileStream ( string filename )
195
+ {
196
+ try
197
+ {
198
+ using var mmf = MemoryMappedFile . CreateFromFile ( filename , FileMode . Open ) ;
199
+ return mmf . CreateViewStream ( ) ;
200
+ }
201
+ catch ( SecurityException ex )
202
+ {
203
+ Console . WriteLine ( $ "Insufficient access right to create memory mapped file: { ex . Message } ") ;
204
+ Console . WriteLine ( "Fallback to slow disk access." ) ;
205
+
206
+ // Fallback on slow path.
207
+ return File . OpenRead ( filename ) ;
208
+ }
209
+ }
210
+
192
211
private void ProcessPackageFile ( string packageFullFilename )
193
212
{
194
- using ( reader = new BinaryReader ( File . OpenRead ( packageFullFilename ) , Encoding . UTF8 , false ) )
213
+ using Stream stream = GetFileStream ( packageFullFilename ) ;
214
+
215
+ using ( reader = new BinaryReader ( stream , Encoding . UTF8 , false ) )
195
216
{
196
217
int totalParentCount = ReadHeader ( ) ;
197
218
You can’t perform that action at this time.
0 commit comments