-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShardFile.cs
More file actions
36 lines (31 loc) · 1.07 KB
/
ShardFile.cs
File metadata and controls
36 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace MurrayGrant.MassiveSort
{
public sealed class ShardFile : IDisposable
{
// The Name property of the FileStream class isn't a simple field access, but does a security check as well.
// This eventually takes out some locks in native code, which can (and does) deadlock with 4+ CPUs.
public readonly string FullPath;
public readonly string Name;
public readonly FileStream Stream;
public ShardFile(string fullPath, int bufferSize)
{
this.FullPath = fullPath;
this.Name = Path.GetFileName(fullPath);
this.Stream = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, bufferSize);
}
public void Dispose()
{
try
{
this.Stream.Dispose();
}
catch (ObjectDisposedException) { }
}
}
}