-
Notifications
You must be signed in to change notification settings - Fork 26
Alternate Data Streams
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.
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);
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);
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());
}