Opens an existing fragmented file store, to create a new one call the CreateNew() static
Syntax
Parameters
- streamFactory
- An IFactory that produces streams for a storage
- blockSize
- The block size to be used for allocations
- growthRate
- The number of blocks to grow the file by when needed, or zero for on-demand
- cacheLimit
- The number of threads that can simultaneously access the file
Example
Library/Library.Test/TestFragmentedFile.cs
C# | Copy Code |
---|
SharedMemoryStream shared = new SharedMemoryStream();
FragmentedFile.CreateNew(shared, 512, 100, 2).Dispose();
using (FragmentedFile ff = new FragmentedFile(shared, 512, 100, 2))
{
long id;
byte[] bytes = MakeBytes(255);
using (Stream write = ff.Create(out id))
using (ITransactable trans = (ITransactable)write)
{
write.Write(bytes, 0, bytes.Length);
trans.Commit();
Assert.AreEqual(bytes, IOStream.ReadAllBytes(ff.Open(id, FileAccess.Read)));
trans.Rollback();
}
AssertThrows<InvalidDataException>(delegate() { ff.Open(id, FileAccess.Read); });
} |
VB.NET | Copy Code |
---|
Dim [shared] As New SharedMemoryStream()
FragmentedFile.CreateNew([shared], 512, 100, 2).Dispose()
Using ff As New FragmentedFile([shared], 512, 100, 2)
Dim id As Long
Dim bytes As Byte() = MakeBytes(255)
Using write As Stream = ff.Create(id)
Using trans As ITransactable = DirectCast(write, ITransactable)
write.Write(bytes, 0, bytes.Length)
trans.Commit()
Assert.AreEqual(bytes, IOStream.ReadAllBytes(ff.Open(id, FileAccess.Read)))
trans.Rollback()
End Using
End Using
AssertThrows(Of InvalidDataException)(Function() Do
ff.Open(id, FileAccess.Read)
End Function)
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also