Parameters
- identity
- A unique integer id for the block to be used with Open/Delete
Return Value
The stream to write to the newly created blockLibrary/Library.Test/TestFragmentedFile.cs
C# | Copy Code |
---|---|
using (SharedMemoryStream shared = new SharedMemoryStream()) using (FragmentedFile ff = FragmentedFile.CreateNew(shared, 512, 100, 2)) { long id; using (Stream write = ff.Create(out id)) PrimitiveSerializer.Int64.WriteTo(id, write); using (Stream read = ff.Open(id, FileAccess.Read)) { Assert.IsTrue(read.CanRead); Assert.IsFalse(read.CanWrite); Assert.IsFalse(read.CanSeek); Assert.AreEqual(id, PrimitiveSerializer.Int64.ReadFrom(read)); read.Flush();//no-op AssertThrows<NotSupportedException>(delegate() { read.Position = 0; }); AssertThrows<NotSupportedException>(delegate() { GC.KeepAlive(read.Position); }); AssertThrows<NotSupportedException>(delegate() { GC.KeepAlive(read.Length); }); AssertThrows<NotSupportedException>(delegate() { read.SetLength(1); }); AssertThrows<NotSupportedException>(delegate() { read.Seek(1, SeekOrigin.Begin); }); AssertThrows<NotSupportedException>(delegate() { read.WriteByte(1); }); } } |
VB.NET | Copy Code |
---|---|
Using [shared] As New SharedMemoryStream() Using ff As FragmentedFile = FragmentedFile.CreateNew([shared], 512, 100, 2) Dim id As Long Using write As Stream = ff.Create(id) PrimitiveSerializer.Int64.WriteTo(id, write) End Using Using read As Stream = ff.Open(id, FileAccess.Read) Assert.IsTrue(read.CanRead) Assert.IsFalse(read.CanWrite) Assert.IsFalse(read.CanSeek) Assert.AreEqual(id, PrimitiveSerializer.Int64.ReadFrom(read)) read.Flush() 'no-op AssertThrows(Of NotSupportedException)(Function() Do read.Position = 0 End Function) AssertThrows(Of NotSupportedException)(Function() Do GC.KeepAlive(read.Position) End Function) AssertThrows(Of NotSupportedException)(Function() Do GC.KeepAlive(read.Length) End Function) AssertThrows(Of NotSupportedException)(Function() Do read.SetLength(1) End Function) AssertThrows(Of NotSupportedException)(Function() Do read.Seek(1, SeekOrigin.Begin) End Function) AssertThrows(Of NotSupportedException)(Function() Do read.WriteByte(1) End Function) End Using End Using End Using |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
FragmentedFile ClassFragmentedFile Members
Overload List