SmbFile

class SmbFile : AutoCloseable

Represents an open handle to a remote SMB file.

Provides offset-based reads (read, readInto) and writes (write), byte-range exclusive or shared locking (lock / unlock), and file truncation or extension (setLength).

Properties

Link copied to clipboard
Link copied to clipboard
val isClosed: Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val size: Long

Functions

Link copied to clipboard
fun asRawSink(startOffset: Long = 0, closeFileOnClose: Boolean = true): RawSink

Returns a kotlinx.io.RawSink that writes to this file.

Link copied to clipboard
fun asRawSource(startOffset: Long = 0, closeFileOnClose: Boolean = true): RawSource

Returns a kotlinx.io.RawSource that reads from this file.

Link copied to clipboard
fun asSink(startOffset: Long = 0, closeFileOnClose: Boolean = true): Sink

Returns a buffered kotlinx.io.Sink that writes to this file.

Link copied to clipboard
fun asSource(startOffset: Long = 0, closeFileOnClose: Boolean = true): Source

Returns a buffered kotlinx.io.Source that reads from this file.

Link copied to clipboard
open override fun close()
Link copied to clipboard
suspend fun closeSuspend()

Closes the file handle on the server (SMB2 CLOSE).

Link copied to clipboard
suspend fun flush()

Flushes server-side write buffers for this file to persistent storage (SMB2 FLUSH).

Link copied to clipboard
suspend fun lock(offset: Long = 0, length: Long = Long.MAX_VALUE, exclusive: Boolean = true, failImmediately: Boolean = true)

Acquires an exclusive or shared byte-range lock on the file (SMB2 LOCK).

Link copied to clipboard
suspend fun read(offset: Long, length: Int): ByteArray

Reads up to length bytes starting at offset. Requests exceeding the server's MaxReadSize are automatically split into chunks.

Link copied to clipboard
suspend fun readAll(): ByteArray

Reads all bytes from the beginning of the file to the end.

Link copied to clipboard
suspend fun readInto(offset: Long, destination: ByteArray, destinationOffset: Int = 0, length: Int = destination.size - destinationOffset): Int

Reads up to length bytes starting at offset directly into destination at destinationOffset without allocating intermediate byte arrays.

Link copied to clipboard
suspend fun setLength(newSize: Long)

Truncates or extends the file to newSize bytes (FileEndOfFileInformation).

Link copied to clipboard
fun toRandomAccessFile(path: String = "", mode: SmbRandomAccessMode = SmbRandomAccessMode.READ_WRITE, bufferSize: Int = SmbRandomAccessFile.DEFAULT_BUFFER_SIZE): SmbRandomAccessFile

Wraps this open file handle in an SmbRandomAccessFile.

Link copied to clipboard
suspend fun unlock(offset: Long = 0, length: Long = Long.MAX_VALUE)

Releases a byte-range lock previously acquired with lock (SMB2 LOCK with SMB2_LOCKFLAG_UNLOCK).

Link copied to clipboard
suspend fun write(offset: Long, data: ByteArray, startIndex: Int = 0, length: Int = data.size - startIndex): Int

Writes a slice of data starting at file offset. Payloads exceeding the server's MaxWriteSize are automatically split into chunks.