Click here to Skip to main content
13,095,658 members (52,257 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

385.6K views
4.7K downloads
129 bookmarked
Posted 31 Jul 2002

Accessing alternative data-streams of files on an NTFS volume

, 15 Aug 2016
A pair of classes to encapsulate access to NTFS alternative data streams.
using System;
using System.IO;
using Trinet.Core.IO.Ntfs;

namespace NTFS
{
	public sealed class StreamInfo
	{
		private readonly AlternateDataStreamInfo _stream;
		
		internal StreamInfo(AlternateDataStreamInfo stream)
		{
			_stream = stream;
		}
		
		public string Name
		{
			get { return _stream.Name; }
		}
		
		public long Size
		{
			get { return _stream.Size; }
		}
		
		public override int GetHashCode()
		{
			return _stream.GetHashCode();
		}
		
		public override string ToString()
		{
			return _stream.ToString();
		}
		
		public override bool Equals(object obj)
		{
			if (object.ReferenceEquals(null, obj)) return false;
			if (object.ReferenceEquals(this, obj)) return true;
			
			StreamInfo info = obj as StreamInfo;
			if (null != info) return _stream.Equals(info._stream);
			
			AlternateDataStreamInfo other = obj as AlternateDataStreamInfo;
			if (null != other) return _stream.Equals(other);
			
			string path = obj as string;
			if (null != path) return string.Equals(path, _stream.FullPath, StringComparison.OrdinalIgnoreCase);
			
			return false;
		}
		
		public FileStream Open(FileMode mode, FileAccess access, FileShare share)
		{
			return _stream.Open(mode, access, share);
		}
		
		public FileStream Open(FileMode mode, FileAccess access)
		{
			return this.Open(mode, access, FileShare.None);
		}
		
		public FileStream Open(FileMode mode)
		{
			return this.Open(mode, FileAccess.ReadWrite, FileShare.None);
		}
		
		public FileStream Open()
		{
			return this.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
		}
		
		public bool Delete()
		{
			return _stream.Delete();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Richard Deeming
Software Developer Nevalee Business Solutions
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 15 Aug 2016
Article Copyright 2002 by Richard Deeming
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid