Skip to main content

TinyFileSystem Class

Namespace: GHIElectronics.TinyCLR.IO.TinyFileSystem · Assembly: GHIElectronics.TinyCLR.IO.TinyFileSystem

Tiny File System provides a basic file system which can be overlayed on any device providing a concrete implementation of the IBlockDriver interface.

public class TinyFileSystem : IDisposable

Methods

Mount()

public void Mount()

Mount an existing file system from a device.

Format()

public void Format()

Formats the device.

Compact()

public void Compact()

Compacts the file system.

Copy(string sourceFileName, string destFileName, bool overwrite)

public void Copy(string sourceFileName, string destFileName, bool overwrite = true)

Copies a file to a new file.

ParameterTypeDescription
sourceFileNamestringThe file to copy.
destFileNamestringThe name of the destination file
overwriteboolSpecifies if the destination should be overwritten if it already exists. Default true.

Create(string fileName, int bufferSize)

public Stream Create(string fileName, int bufferSize = 4096)

Creates or overwrites a file.

ParameterTypeDescription
fileNamestringName of the file to create.
bufferSizeintSize of the read/write buffer. 0 for no buffering.

Returns Stream — TinyFileStream that provides stream based access to the file.

Delete(string fileName)

public void Delete(string fileName)

Deletes a file from the device.

ParameterTypeDescription
fileNamestringName of the file to delete.

Exists(string fileName)

public bool Exists(string fileName)

Determines if the specified file exists.

ParameterTypeDescription
fileNamestringName of the file to check.

Returns bool — true if the file exists otherwise false.

Move(string sourceFileName, string destFileName)

public void Move(string sourceFileName, string destFileName)

Moves a file from the source to the destination.

ParameterTypeDescription
sourceFileNamestringName of the file to move.
destFileNamestringNew name of the file.

Open(string fileName, FileMode fileMode, int bufferSize)

public Stream Open(string fileName, FileMode fileMode, int bufferSize = 4096)

Opens a TinyFileStream for the specified file.

ParameterTypeDescription
fileNamestringName of the file to open.
fileModeFileModeSpecifies what to do when opening the file.
bufferSizeintSize of the read/write buffer. 0 for no buffering.

Returns Stream — A TinyFileStream which provides stream based access to the file.

ReadAllBytes(string fileName)

public byte[] ReadAllBytes(string fileName)

Opens a file, reads the content into a byte array and then closes the file.

ParameterTypeDescription
fileNamestringName of the file to read.

Returns byte[] — A byte array containing the data from the file.

WriteAllBytes(string fileName, byte[] data)

public void WriteAllBytes(string fileName, byte[] data)

Creates a new file, writes the byte array to the file and then closes it. The file is overwritten if it already exists.

ParameterTypeDescription
fileNamestringName of the file to create.
databyte[]Bytes to be written to the file.

GetFiles()

public string[] GetFiles()

Returns the names of the files in the file system.

Returns string[] — An array of the names of the files.

GetFileSize(string fileName)

public long GetFileSize(string fileName)

Gets the size of the specified file.

ParameterTypeDescription
fileNamestringName of the file for which to retrieve the file size.

Returns long — Size of the file in bytes.

GetFileCreationTime(string fileName)

public DateTime GetFileCreationTime(string fileName)

Gets the creation time of the specified file.

ParameterTypeDescription
fileNamestringName of the file for which to retrieve the creation time.

Returns DateTime — The creation time of the specified file.

GetStats()

public DeviceStats GetStats()

Get the current statistics of the file system.

Returns DeviceStats — Structure with the statistics of the file system.

Dispose(bool disposing)

protected void Dispose(bool disposing)

Closes a response stream, if present. (inherited)

ParameterTypeDescription
disposingboolNot used.

Dispose()

public void Dispose()

Releases buffered memory (the unmanaged firmware/application buffers). (inherited)