You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thong Nguyen edited this page May 26, 2013
·
3 revisions
NTFS supports Alternate Data Streams. These allow more than one data stream to be associated with a file name. Platform.VirtualFileSystem supports easily listing, reading and writing to alternate data streams.
Listing available streams
List available streams by using INode.GetContentNames(). By default all files that exist on NTFS will contain a single stream named $DATA.
var file = FileSystemManager.Default.ResolveFile("temp://test.txt");
file.Create();
// Should output: $DATA
file.GetContentNames().ForEach(Console.WriteLine);
Writing to an alternate data stream
You can write a new stream by writing to a named INodeContent.
var file = FileSystemManager.Default.ResolveFile("temp://test.txt");
using (var writer = file.GetContent("MyAlternateData").GetWriter())
{
writer.Write("Hello");
}
// Should output: $DATA, Hello
file.GetContentNames().ForEach(Console.WriteLine);
Reading from an alternate data stream
You can now read back from that stream using the named INodeContent.
var file = FileSystemManager.Default.ResolveFile("temp://test.txt");
using (var reader = file.GetContent("MyAlternateData").GetReader())
{
// Should output Hello
Console.WriteLine(reader.ReadToEnd());
}