Skip to content

Latest commit

 

History

History
263 lines (241 loc) · 12.6 KB

File metadata and controls

263 lines (241 loc) · 12.6 KB

System.IO


DirectoryInfoExtensions

Provides extension methods for the DirectoryInfo class.

public static class DirectoryInfoExtensions

Static Methods

CombineFileInfo

FileInfo CombineFileInfo(this DirectoryInfo directoryInfo, string[] paths)

Summary: Combines the directory path with additional sub-paths to create a FileInfo object.

Parameters:
     directoryInfo  -  The base directory information.
     paths  -  An array of sub-paths to combine with the base directory.

Returns: A FileInfo object representing the combined path.

GetByteSize

long GetByteSize(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)

Summary: Calculates the total size in bytes of all files in the directory matching the search pattern.

Parameters:
     directoryInfo  -  The directory to calculate size for.
     searchPattern  -  The search pattern to match file names against (e.g., ".txt"). Defaults to ".*" for all files.
     searchOption  -  Specifies whether to search only the current directory or all subdirectories. Defaults to .

Returns: The total size in bytes of all matching files.

GetFileInfo

FileInfo GetFileInfo(this DirectoryInfo directoryInfo, string file)

Summary: Creates a System.IO.FileInfo object for a file within the directory.

Parameters:
     directoryInfo  -  The directory containing the file.
     file  -  The file name (without path) to get information for.

Returns: A System.IO.FileInfo object representing the combined directory and file name.

GetFilesCount

long GetFilesCount(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)

Summary: Counts the total number of files in the directory matching the search pattern.

Parameters:
     directoryInfo  -  The directory to search in.
     searchPattern  -  The search pattern to match file names against (e.g., ".txt"). Defaults to ".*" for all files.
     searchOption  -  Specifies whether to search only the current directory or all subdirectories. Defaults to .

Returns: The total number of files found.

GetFilesForAuthorizedAccess

FileInfo[] GetFilesForAuthorizedAccess(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = TopDirectoryOnly)

Summary: Gets all files matching the search pattern while gracefully skipping files and folders with unauthorized access.

Parameters:
     directoryInfo  -  The directory to search in.
     searchPattern  -  The search pattern to match file names against (e.g., ".txt"). Defaults to ".*" for all files.
     searchOption  -  Specifies whether to search only the current directory or all subdirectories. Defaults to .

Returns: An array of System.IO.FileInfo objects representing the files found.

GetFoldersCount

long GetFoldersCount(this DirectoryInfo directoryInfo, string searchPattern = *, SearchOption searchOption = AllDirectories)

Summary: Counts the total number of subdirectories in the directory matching the search pattern.

Parameters:
     directoryInfo  -  The directory to search in.
     searchPattern  -  The search pattern to match directory names against (e.g., "temp*"). Defaults to "*" for all directories.
     searchOption  -  Specifies whether to search only the current directory or all subdirectories. Defaults to .

Returns: The total number of subdirectories found.

GetPrettyByteSize

string GetPrettyByteSize(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)

Summary: Gets the byte size as pretty formatted text like '1.933.212.103 bytes'.

Parameters:
     directoryInfo  -  The directory information.
     searchPattern  -  The search pattern.
     searchOption  -  The search option.

GetPrettySize

string GetPrettySize(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)

Summary: Gets the byte size as pretty formatted text like '1.82 GB'.

Parameters:
     directoryInfo  -  The directory information.
     searchPattern  -  The search pattern.
     searchOption  -  The search option.


FileInfoExtensions

Extension methods for the System.IO.FileInfo class.

public static class FileInfoExtensions

Static Methods

ReadToByteArray

byte[] ReadToByteArray(this FileInfo fileInfo)

Summary: Reads all bytes from the file into a byte array.

Parameters:
     fileInfo  -  The file information representing the file to read.

Returns: A byte array containing all data from the file.

ReadToByteArrayAsync

Task<byte[]> ReadToByteArrayAsync(this FileInfo fileInfo, CancellationToken cancellationToken = null)

Summary: Asynchronously reads all bytes from the file into a byte array.

Parameters:
     fileInfo  -  The file information representing the file to read.
     cancellationToken  -  A cancellation token to observe while waiting for the asynchronous operation to complete.

Returns: A task that represents the asynchronous read operation. The task result contains a byte array with all data from the file.

ReadToMemoryStream

MemoryStream ReadToMemoryStream(this FileInfo fileInfo)

Summary: Reads the file content into a System.IO.MemoryStream.

Parameters:
     fileInfo  -  The file information representing the file to read.

Returns: A System.IO.MemoryStream containing the file content with position set to 0.

ReadToMemoryStreamAsync

Task<MemoryStream> ReadToMemoryStreamAsync(this FileInfo fileInfo, CancellationToken cancellationToken = null)

Summary: Asynchronously reads the file content into a System.IO.MemoryStream.

Parameters:
     fileInfo  -  The file information representing the file to read.
     cancellationToken  -  A cancellation token to observe while waiting for the asynchronous operation to complete.

Returns: A task that represents the asynchronous read operation. The task result contains a System.IO.MemoryStream with the file content and position set to 0.


MemoryStreamExtensions

Extensions for the System.IO.MemoryStream class.

public static class MemoryStreamExtensions

Static Methods

ToString

string ToString(this MemoryStream stream, Encoding encoding = null)

Summary: Converts the memory stream content to a string using the specified encoding.

Parameters:
     stream  -  The memory stream to convert.
     encoding  -  The encoding to use for the conversion. Defaults to when .

Returns: A string representation of the memory stream content.


StreamExtensions

Extensions for the System.IO.Stream class.

public static class StreamExtensions

Static Methods

CopyToStream

Stream CopyToStream(this Stream stream, int bufferSize = 4096)

Summary: Copies the contents of the stream to a new System.IO.MemoryStream.

Parameters:
     stream  -  The source stream to copy from. The stream position will be reset to 0 before copying.
     bufferSize  -  The size of the buffer used for copying. Defaults to 4096 bytes.

Returns: A new System.IO.MemoryStream containing the copied data with position set to 0.

CopyToStreamAsync

Task<Stream> CopyToStreamAsync(this Stream stream, int bufferSize = 4096, CancellationToken cancellationToken = null)

Summary: Asynchronously copies the contents of the stream to a new System.IO.MemoryStream.

Parameters:
     stream  -  The source stream to copy from. The stream position will be reset to 0 before copying if the stream supports seeking.
     bufferSize  -  The size of the buffer used for copying. Defaults to 4096 bytes.
     cancellationToken  -  A token to cancel the asynchronous operation.

Returns: A System.Threading.Tasks.Task1that represents the asynchronous operation, containing a newSystem.IO.MemoryStream` with position set to 0.

ToBytes

byte[] ToBytes(this Stream stream)

Summary: Reads all bytes from the stream and returns them as a byte array.

Parameters:
     stream  -  The stream to read from. The stream position will be reset to 0 before reading.

Returns: A byte array containing all data from the stream.

ToBytesAsync

Task<byte[]> ToBytesAsync(this Stream stream, CancellationToken cancellationToken = null)

Summary: Asynchronously reads all bytes from the stream and returns them as a byte array.

Parameters:
     stream  -  The stream to read from. The stream position will be reset to 0 before reading if the stream supports seeking.
     cancellationToken  -  A token to cancel the asynchronous operation.

Returns: A System.Threading.Tasks.Task1` that represents the asynchronous operation, containing a byte array with all data from the stream.

ToStringData

string ToStringData(this Stream stream)

Summary: Reads all content from the stream and converts it to a string using the default encoding.

Parameters:
     stream  -  The stream to read from. The stream position will be reset to 0 before reading.

Returns: A string containing all text content from the stream.

ToStringDataAsync

Task<string> ToStringDataAsync(this Stream stream, CancellationToken cancellationToken = null)

Summary: Asynchronously reads all content from the stream and converts it to a string using UTF-8 encoding.

Parameters:
     stream  -  The stream to read from. The stream position will be reset to 0 before reading if the stream supports seeking.
     cancellationToken  -  A token to cancel the asynchronous operation.

Returns: A System.Threading.Tasks.Task1` that represents the asynchronous operation, containing a string with all text content from the stream.


Generated by MarkdownCodeDoc version 1.2