Class MtFile
- Namespace
- SharpPluginLoader.Core.IO
- Assembly
- SharpPluginLoader.Core.dll
Represents a file.
public class MtFile : MtObject, IDisposable
- Inheritance
-
MtFile
- Implements
- Inherited Members
Constructors
MtFile()
public MtFile()
MtFile(nint)
public MtFile(nint instance)
Parameters
instancenint
Properties
IsReadable
Whether the file is readable.
public bool IsReadable { get; }
Property Value
IsWritable
Whether the file is writable.
public bool IsWritable { get; }
Property Value
Path
Gets the path of the file.
public string Path { get; }
Property Value
Position
Gets the file pointer.
public long Position { get; }
Property Value
Size
Gets the size of the file.
public long Size { get; }
Property Value
Methods
Close()
Closes the file.
public void Close()
Remarks
This is called automatically when the file object is destroyed or disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
~MtFile()
protected ~MtFile()
Open(string, OpenMode, bool)
Opens a file.
public static MtFile? Open(string path, OpenMode mode, bool createPath = true)
Parameters
pathstringThe path of the file.
modeOpenModeThe mode to open the file in.
createPathboolWhether to create the path if it does not exist.
Returns
- MtFile
The opened file, or null if the file could not be opened.
Read(long)
Reads the specified number of bytes from the file.
public byte[] Read(long size)
Parameters
sizelongThe number of bytes to read.
Returns
- byte[]
The bytes read.
Exceptions
- Exception
Thrown if the number of bytes read does not match the number of bytes requested.
Read(Span<byte>, long)
Reads the specified number of bytes from the file.
public long Read(Span<byte> buffer, long count = -1)
Parameters
bufferSpan<byte>The buffer to read into.
countlongThe number of bytes to read. If -1, it will read bytes equal to the length of the buffer.
Returns
- long
The number of bytes read.
Reopen(string, OpenMode, bool)
Reopens the file.
public bool Reopen(string path, OpenMode mode, bool createPath = true)
Parameters
pathstringThe path of the file.
modeOpenModeThe mode to open the file in.
createPathboolWhether to create the path if it does not exist.
Returns
- bool
Whether the file was reopened successfully.
Seek(long, SeekOrigin)
Seeks to the specified position in the file.
public long Seek(long offset, SeekOrigin origin)
Parameters
offsetlongThe offset to seek to.
originSeekOriginThe origin to seek from.
Returns
- long
The new position in the file.
SetLength(long)
Sets the length of the file.
public void SetLength(long length)
Parameters
lengthlongThe new length of the file.
Write(ReadOnlySpan<byte>)
Writes the specified bytes to the file.
public long Write(ReadOnlySpan<byte> buffer)
Parameters
bufferReadOnlySpan<byte>The bytes to write.
Returns
- long
The number of bytes written.