MtFile
Namespace: SharpPluginLoader.Core.IO
Represents a file.
public class MtFile : SharpPluginLoader.Core.MtObject, System.IDisposable
Inheritance Object → NativeWrapper → MtObject → MtFile
Implements IDisposable
Properties
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
IsReadable
Whether the file is readable.
public bool IsReadable { get; }
Property Value
IsWritable
Whether the file is writable.
public bool IsWritable { get; }
Property Value
Instance
The native pointer.
public nint Instance { get; set; }
Property Value
Constructors
MtFile(IntPtr)
public MtFile(nint instance)
Parameters
instance
IntPtr
MtFile()
public MtFile()
Methods
Open(String, OpenMode, Boolean)
Opens a file.
public static MtFile Open(string path, OpenMode mode, bool createPath)
Parameters
path
String
The path of the file.
mode
OpenMode
The mode to open the file in.
createPath
Boolean
Whether to create the path if it does not exist.
Returns
MtFile
The opened file, or null if the file could not be opened.
Reopen(String, OpenMode, Boolean)
Reopens the file.
public bool Reopen(string path, OpenMode mode, bool createPath)
Parameters
path
String
The path of the file.
mode
OpenMode
The mode to open the file in.
createPath
Boolean
Whether to create the path if it does not exist.
Returns
Boolean
Whether the file was reopened successfully.
Close()
Closes the file.
public void Close()
Remarks:
This is called automatically when the file object is destroyed or disposed.
Read(Int64)
Reads the specified number of bytes from the file.
public Byte[] Read(long size)
Parameters
size
Int64
The 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>, Int64)
Reads the specified number of bytes from the file.
public long Read(Span<byte> buffer, long count)
Parameters
buffer
Span<Byte>
The buffer to read into.
count
Int64
The number of bytes to read. If -1, it will read bytes equal to the length of the buffer.
Returns
Int64
The number of bytes read.
Write(ReadOnlySpan<Byte>)
Writes the specified bytes to the file.
public long Write(ReadOnlySpan<byte> buffer)
Parameters
buffer
ReadOnlySpan<Byte>
The bytes to write.
Returns
Int64
The number of bytes written.
Seek(Int64, SeekOrigin)
Seeks to the specified position in the file.
public long Seek(long offset, SeekOrigin origin)
Parameters
offset
Int64
The offset to seek to.
origin
SeekOrigin
The origin to seek from.
Returns
Int64
The new position in the file.
SetLength(Int64)
Sets the length of the file.
public void SetLength(long length)
Parameters
length
Int64
The new length of the file.
Dispose()
public void Dispose()
Finalize()
protected void Finalize()