PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.AutoTempFolder Class Reference

Provides a mechanism for creating a temporary folder which is automatically deleted upon disposal. More...

Inheritance diagram for PeanutButter.Utils.AutoTempFolder:
PeanutButter.Utils.IAutoTempFolder

Public Member Functions

 AutoTempFolder ()
 Default constructor: uses the operating system method to get a temporary path to use for the folder.
 AutoTempFolder (string baseFolder)
 Constructs a new AutoTempFolder with the temporary folder housed under the provided baseFolder.
void Dispose ()
string ResolvePath (string p1, params string[] more)
 Resolves a relative path (or path parts) within the auto temp folder.
  • note: this doesn't guarantee that the path exists
Parameters
p1
more
Returns

IEnumerable< string > ResolvePaths (IEnumerable< string > relativePaths)
 Resolves all provided relative paths within the temp folder.
  • note: this doesn't guarantee that the path exists
Parameters
relativePaths
Returns

string CreateFolder (string dirname)
 Creates a directory within the auto temp folder.
  • any supporting directories will also be created
Parameters
dirname
Returns

string WriteFile (string filename, string data)
 Writes a file within the auto temp folder.
Parameters
filenamerelative path to the file
datastring data to write
Returns
full path to the written file

string WriteFile (string filename, byte[] data)
 Writes a file within the auto temp folder.
Parameters
filenamerelative path to the file
databinary data to write
Returns
full path to the written file

string WriteFile (string filename, Stream data)
 Writes a file within the auto temp folder.
Parameters
filenamerelative path to the file
datastream data to write
Returns
full path to the written file

string ReadTextFile (string filename)
 Reads a text file by relative path within the auto temp folder.
Parameters
filename
Returns

byte[] ReadFile (string filename)
 Reads a binary file by relative path within the auto temp folder.
Parameters
filename
Returns

FileStream OpenFile (string filename)
 Opens a file (read-only) by relative path within the auto temp folder.
Parameters
filename
Returns

FileStream OpenFile (string filename, FileAccess access)
 Opens a file by relative path within the auto temp folder with the desired access.
  • defaulted share is None
  • defaulted buffer size is 4096
  • defaulted options is None
Parameters
filename
access
Returns

FileStream OpenFile (string filename, FileAccess access, FileShare share)
 Opens a file by relative path within the auto temp folder with the desired access and share.
  • defaulted buffer size is 4096
  • defaulted options is None
Parameters
filename
access
share

FileStream OpenFile (string filename, FileAccess access, FileShare share, int bufferSize)
 Opens a file by relative path within the auto temp folder with the desired access, share and buffer size.
  • defaulted options is None
Parameters
filename
access
share
bufferSize

FileStream OpenFile (string filename, FileAccess access, FileShare share, int bufferSize, FileOptions options)
 Opens a file by relative path within the auto temp folder with the desired access, share, buffer size and options.
Parameters
filename
access
share
bufferSize
options

bool FileExists (string relativePath)
 Returns true if the relative path is found to be a file.
Parameters
relativePath
Returns

bool FolderExists (string relativePath)
 Returns true if the relative path is found to be a folder.
Parameters
relativePath
Returns

bool Exists (string relativePath)
 Returns true if the relative path is a file or folder.
Parameters
relativePath
Returns

bool Contains (string fullPath)
 Returns true if the provided path is contained within the temp folder.
Parameters
fullPath
Returns

Static Public Attributes

const FileAccess DEFAULT_FILE_ACCESS = FileAccess.Read
 Default file access, as per System.IO.FileStream.
const FileShare DEFAULT_FILE_SHARE = FileShare.None
 Default file share mode as per System.IO.FileStream.
const int DEFAULT_BUFFER_SIZE = 4096
 Default buffer size as per System.IO.FileStream.
const FileOptions DEFAULT_FILE_OPTIONS = FileOptions.None
 Default file options, as per System.IO.FileStream.

Properties

int RetryOperations [get, set]
 How many times to retry operations if they fail.
string Path [get]
 The local path at which this temp folder exists.

Detailed Description

Provides a mechanism for creating a temporary folder which is automatically deleted upon disposal.

Constructor & Destructor Documentation

◆ AutoTempFolder()

PeanutButter.Utils.AutoTempFolder.AutoTempFolder ( string baseFolder)

Constructs a new AutoTempFolder with the temporary folder housed under the provided baseFolder.

Parameters
baseFolderFolder within which to create the temporary folder

Member Function Documentation

◆ Contains()

bool PeanutButter.Utils.AutoTempFolder.Contains ( string fullPath)

Returns true if the provided path is contained within the temp folder.

Parameters
fullPath
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ CreateFolder()

string PeanutButter.Utils.AutoTempFolder.CreateFolder ( string dirname)

Creates a directory within the auto temp folder.

  • any supporting directories will also be created
Parameters
dirname
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ Exists()

bool PeanutButter.Utils.AutoTempFolder.Exists ( string relativePath)

Returns true if the relative path is a file or folder.

Parameters
relativePath
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ FileExists()

bool PeanutButter.Utils.AutoTempFolder.FileExists ( string relativePath)

Returns true if the relative path is found to be a file.

Parameters
relativePath
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ FolderExists()

bool PeanutButter.Utils.AutoTempFolder.FolderExists ( string relativePath)

Returns true if the relative path is found to be a folder.

Parameters
relativePath
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ OpenFile() [1/5]

FileStream PeanutButter.Utils.AutoTempFolder.OpenFile ( string filename)

Opens a file (read-only) by relative path within the auto temp folder.

Parameters
filename
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ OpenFile() [2/5]

FileStream PeanutButter.Utils.AutoTempFolder.OpenFile ( string filename,
FileAccess access )

Opens a file by relative path within the auto temp folder with the desired access.

  • defaulted share is None
  • defaulted buffer size is 4096
  • defaulted options is None
Parameters
filename
access
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ OpenFile() [3/5]

FileStream PeanutButter.Utils.AutoTempFolder.OpenFile ( string filename,
FileAccess access,
FileShare share )

Opens a file by relative path within the auto temp folder with the desired access and share.

  • defaulted buffer size is 4096
  • defaulted options is None
Parameters
filename
access
share

Implements PeanutButter.Utils.IAutoTempFolder.

◆ OpenFile() [4/5]

FileStream PeanutButter.Utils.AutoTempFolder.OpenFile ( string filename,
FileAccess access,
FileShare share,
int bufferSize )

Opens a file by relative path within the auto temp folder with the desired access, share and buffer size.

  • defaulted options is None
Parameters
filename
access
share
bufferSize

Implements PeanutButter.Utils.IAutoTempFolder.

◆ OpenFile() [5/5]

FileStream PeanutButter.Utils.AutoTempFolder.OpenFile ( string filename,
FileAccess access,
FileShare share,
int bufferSize,
FileOptions options )

Opens a file by relative path within the auto temp folder with the desired access, share, buffer size and options.

Parameters
filename
access
share
bufferSize
options

Implements PeanutButter.Utils.IAutoTempFolder.

◆ ReadFile()

byte[] PeanutButter.Utils.AutoTempFolder.ReadFile ( string filename)

Reads a binary file by relative path within the auto temp folder.

Parameters
filename
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ ReadTextFile()

string PeanutButter.Utils.AutoTempFolder.ReadTextFile ( string filename)

Reads a text file by relative path within the auto temp folder.

Parameters
filename
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ ResolvePath()

string PeanutButter.Utils.AutoTempFolder.ResolvePath ( string p1,
params string[] more )

Resolves a relative path (or path parts) within the auto temp folder.

  • note: this doesn't guarantee that the path exists
Parameters
p1
more
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ ResolvePaths()

IEnumerable< string > PeanutButter.Utils.AutoTempFolder.ResolvePaths ( IEnumerable< string > relativePaths)

Resolves all provided relative paths within the temp folder.

  • note: this doesn't guarantee that the path exists
Parameters
relativePaths
Returns

Implements PeanutButter.Utils.IAutoTempFolder.

◆ WriteFile() [1/3]

string PeanutButter.Utils.AutoTempFolder.WriteFile ( string filename,
byte[] data )

Writes a file within the auto temp folder.

Parameters
filenamerelative path to the file
databinary data to write
Returns
full path to the written file

Implements PeanutButter.Utils.IAutoTempFolder.

◆ WriteFile() [2/3]

string PeanutButter.Utils.AutoTempFolder.WriteFile ( string filename,
Stream data )

Writes a file within the auto temp folder.

Parameters
filenamerelative path to the file
datastream data to write
Returns
full path to the written file

Implements PeanutButter.Utils.IAutoTempFolder.

◆ WriteFile() [3/3]

string PeanutButter.Utils.AutoTempFolder.WriteFile ( string filename,
string data )

Writes a file within the auto temp folder.

Parameters
filenamerelative path to the file
datastring data to write
Returns
full path to the written file

Implements PeanutButter.Utils.IAutoTempFolder.

Property Documentation

◆ Path

string PeanutButter.Utils.AutoTempFolder.Path
get

The local path at which this temp folder exists.

Implements PeanutButter.Utils.IAutoTempFolder.

◆ RetryOperations

int PeanutButter.Utils.AutoTempFolder.RetryOperations
getset

How many times to retry operations if they fail.

  • operations like read and write are retried on failure as I've seen antivirus hold onto files ):

Implements PeanutButter.Utils.IAutoTempFolder.


The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/AutoTempFolder.cs