Package-level declarations

Types

Link copied to clipboard

Checked exception thrown when a file system operation is denied, typically due to a file permission or other access check.

actual typealias AccessDeniedException = kotlin.io.AccessDeniedException
actual class AccessDeniedException(val file: File, val other: File? = null, val reason: String? = null) : FileSystemException

Checked exception thrown when a file system operation is denied, typically due to a file permission or other access check.

Link copied to clipboard
object ANDROID
Link copied to clipboard
actual value class Buffer

A wrapper value class for a Node.js Buffer object.

expect value class Buffer

A wrapper value class for a Node.js Buffer object.

actual value class Buffer

A wrapper value class for a Node.js Buffer object.

Link copied to clipboard
expect fun interface Closeable

A source or destination of data (such as a File) which can be closed.

actual typealias Closeable = java.io.Closeable
actual fun interface Closeable

A source or destination of data (such as a File) which can be closed.

Link copied to clipboard
expect open class ClosedException : IOException

Checked exception thrown when an attempt is made to invoke or complete an I/O operation upon something that is closed, or at least closed to that operation. That this exception is thrown does not necessarily imply that implementation is completely closed (for a FileStream, it does). A socket whose write half has been shut down, for example, may still be open for reading.

actual open class ClosedException : IOException

Checked exception thrown when an attempt is made to invoke or complete an I/O operation upon something that is closed, or at least closed to that operation. That this exception is thrown does not necessarily imply that implementation is completely closed (for a FileStream, it does). A socket whose write half has been shut down, for example, may still be open for reading.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.TYPEALIAS])
annotation class DelicateFileApi

Denotes an api as being delicate. Probably shouldn't use it.

Link copied to clipboard

Checked exception thrown when a file system operation fails because a directory is not empty.

actual class DirectoryNotEmptyException : FileSystemException

Checked exception thrown when a file system operation fails because a directory is not empty.

Checked exception thrown when a file system operation fails because a directory is not empty.

Link copied to clipboard
expect open class EOFException : IOException

Signals that an end of file or end of stream has been reached unexpectedly during input. This exception is mainly used by data input streams to signal end of stream. Note that many other input operations return a special value on end of stream rather than throwing an exception.

actual open class EOFException : IOException

Signals that an end of file or end of stream has been reached unexpectedly during input. This exception is mainly used by data input streams to signal end of stream. Note that many other input operations return a special value on end of stream rather than throwing an exception.

Link copied to clipboard
expect class File(pathname: String) : Comparable<File>

A File which holds the abstract pathname to a location on the filesystem, be it for a regular file, directory, symbolic link, etc.

actual typealias File = java.io.File
actual class File(pathname: String) : Comparable<File>

A File which holds the abstract pathname to a location on the filesystem, be it for a regular file, directory, symbolic link, etc.

Link copied to clipboard

Checked exception thrown when an attempt is made to create a file or directory and a file of that name already exists.

actual typealias FileAlreadyExistsException = kotlin.io.FileAlreadyExistsException
actual class FileAlreadyExistsException(val file: File, val other: File? = null, val reason: String? = null) : FileSystemException

Checked exception thrown when an attempt is made to create a file or directory and a file of that name already exists.

Link copied to clipboard

Signals that an attempt to open the file or directory denoted by a specified pathname has failed due to its non-existence.

Signals that an attempt to open the file or directory denoted by a specified pathname has failed due to its non-existence.

Link copied to clipboard
expect sealed interface FileStream : Closeable

A stream for a File.

actual interface FileStream : Closeable
actual interface FileStream : Closeable
Link copied to clipboard
expect open class FileSystemException : IOException

Thrown when a file system operation fails on one or two files. This class is the general class for file system exceptions.

actual typealias FileSystemException = kotlin.io.FileSystemException
actual open class FileSystemException(val file: File, val other: File? = null, val reason: String? = null) : IOException

Thrown when a file system operation fails on one or two files. This class is the general class for file system exceptions.

Link copied to clipboard
class FsInfo

Information about the filesystem backing the kmp-file API.

Link copied to clipboard
expect open class InterruptedException : Exception

Thrown when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity.

actual open class InterruptedException : Exception

Thrown when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity.

Link copied to clipboard

Signals that an I/O operation has been interrupted. An InterruptedIOException is thrown to indicate that an input or output transfer has been terminated because the thread performing it was interrupted. The field bytesTransferred indicates how many bytes were successfully transferred before the interruption occurred.

Signals that an I/O operation has been interrupted. An InterruptedIOException is thrown to indicate that an input or output transfer has been terminated because the thread performing it was interrupted. The field bytesTransferred indicates how many bytes were successfully transferred before the interruption occurred.

Link copied to clipboard
expect open class IOException : Exception

Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations.

actual typealias IOException = java.io.IOException
actual open class IOException : Exception

Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations.

Link copied to clipboard

Checked exception thrown when a file system operation, intended for a directory, fails because the file is not a directory.

actual class NotDirectoryException : FileSystemException

Checked exception thrown when a file system operation, intended for a directory, fails because the file is not a directory.

Checked exception thrown when a file system operation, intended for a directory, fails because the file is not a directory.

Link copied to clipboard
sealed class OpenExcl

File open exclusivity.

Link copied to clipboard
actual value class Stats

A wrapper value class for a Node.js filesystem Stats object.

expect value class Stats

A wrapper value class for a Node.js filesystem Stats object.

actual value class Stats

A wrapper value class for a Node.js filesystem Stats object.

Properties

Link copied to clipboard

Reports how many bytes had been transferred as part of the I/O operation before it was interrupted.

Reports how many bytes had been transferred as part of the I/O operation before it was interrupted.

Reports how many bytes had been transferred as part of the I/O operation before it was interrupted.

Link copied to clipboard
actual val Throwable.errorCodeOrNull: String?

Attempts to retrieve the code from an exception thrown from JavaScript. If unable to retrieve it, null is returned.

expect val Throwable.errorCodeOrNull: String?

Attempts to retrieve the code from an exception thrown from JavaScript. If unable to retrieve it, null is returned.

actual val Throwable.errorCodeOrNull: String?

Attempts to retrieve the code from an exception thrown from JavaScript. If unable to retrieve it, null is returned.

Link copied to clipboard
@get:JvmName(name = "nameOf")
val File.name: String

The name of the file or directory.

Link copied to clipboard
@get:JvmName(name = "parentFileOf")
val File.parentFile: File?

The path parent File.

Link copied to clipboard
@get:JvmName(name = "parentPathOf")
val File.parentPath: String?

The path parent.

Link copied to clipboard
@get:JvmName(name = "pathOf")
val File.path: String

The abstract path to a directory or file.

Link copied to clipboard
@JvmField
val SysDirSep: Char

The operating system's directory separator character.

Link copied to clipboard
@get:JvmName(name = "SysFsInfo")
val SysFsInfo: FsInfo

Information about the FileSystem that is backing the File API.

Link copied to clipboard
@JvmField
val SysPathSep: Char

The operating system's PATH environment variable (and others such as LD_LIBRARY_PATH, etc.) delimiter character.

Link copied to clipboard
@JvmField
val SysTempDir: File

The system's temporary directory.

Functions

Link copied to clipboard
@JvmName(name = "absoluteFile2Of")
fun File.absoluteFile2(): File

If this abstract pathname is already absolute, then the pathname File is simply returned.

Link copied to clipboard
@JvmName(name = "absolutePath2Of")
fun File.absolutePath2(): String

If this abstract pathname is already absolute, then the pathname string is simply returned.

Link copied to clipboard
inline fun File.append(excl: OpenExcl?, data: Buffer)

Writes the contents of a Buffer to the file associated with the abstract pathname. If the file exists, all new data will be appended to the end of the file.

Link copied to clipboard
@JvmName(name = "appendBytesTo")
inline fun File.appendBytes(excl: OpenExcl?, array: ByteArray): File

Writes the full contents of array to the file. If the file exists, all new data will be appended to the end of the file.

Link copied to clipboard
@JvmName(name = "appendUtf8To")
inline fun File.appendUtf8(excl: OpenExcl?, text: String): File

Writes the full contents of text to the file. If the file exists, all new text will be appended to the end of the file.

Link copied to clipboard
@JvmName(name = "canonicalFile2Of")
fun File.canonicalFile2(): File

A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent.

Link copied to clipboard
@JvmName(name = "canonicalPath2Of")
fun File.canonicalPath2(): String

A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent.

Link copied to clipboard
@JvmOverloads
fun File.chmod2(mode: String, mustExist: Boolean = true): File

Modifies file or directory permissiveness.

Link copied to clipboard
@JvmOverloads
fun File.delete2(ignoreReadOnly: Boolean = false, mustExist: Boolean = false): File

Deletes the file or directory denoted by this abstract pathname.

Link copied to clipboard
fun errnoToIOException(errno: Int, file: File?, other: File? = null): IOException

Converts platform.posix.errno to a string (e.g. ENOENT "ENOENT") as a prefix for the human-readable error message retrieved via strerror and returns it as an IOException. When platform.posix.errno is ENOENT, then this function will return FileNotFoundException. When platform.posix.errno is EINTR, then this function will return InterruptedIOException.

Link copied to clipboard
fun File.exists2(): Boolean

Tests whether the file or directory denoted by this abstract pathname exists.

Link copied to clipboard
inline operator fun Buffer.get(index: Number): Byte

Helper for Buffer.readInt8

Link copied to clipboard
actual inline fun <T> jsExternTryCatch(block: () -> T): T

Helper for calling externally defined code in order to propagate a proper JS Error. On Kotlin/Js this simply calls block, but on Kotlin/WasmJs block is wrapped in a function call and run from Js within its own try/catch block. If an Error was caught, it is returned to Kotlin code, converted to Throwable, and then thrown.

expect inline fun <T> jsExternTryCatch(crossinline block: () -> T): T

Helper for calling externally defined code in order to propagate a proper JS Error. On Kotlin/Js this simply calls block, but on Kotlin/WasmJs block is wrapped in a function call and run from Js within its own try/catch block. If an Error was caught, it is returned to Kotlin code, converted to Throwable, and then thrown.

actual inline fun <T> jsExternTryCatch(crossinline block: () -> T): T

Helper for calling externally defined code in order to propagate a proper JS Error. On Kotlin/Js this simply calls block, but on Kotlin/WasmJs block is wrapped in a function call and run from Js within its own try/catch block. If an Error was caught, it is returned to Kotlin code, converted to Throwable, and then thrown.

Link copied to clipboard
inline fun lastErrorToIOException(lastError: <Error class: unknown class> = GetLastError()): IOException

Retrieves the human-readable message for GetLastError via FormatMessageA and returns it as an IOException. When the last error is ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND, then this function will return FileNotFoundException. When the last error is ERROR_OPERATION_ABORTED, then this function will return InterruptedIOException. When the last error is ERROR_HANDLE_EOF, then this function returns EOFException.

fun lastErrorToIOException(file: File?, other: File? = null, lastError: <Error class: unknown class> = GetLastError()): IOException

Retrieves the human-readable message for GetLastError via FormatMessageA and returns it as an IOException. When the last error is ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND, then this function will return FileNotFoundException.

Link copied to clipboard

Retrieve the symbolic Stats referred to by the abstract pathname.

Link copied to clipboard
@JvmOverloads
fun File.mkdir2(mode: String?, mustCreate: Boolean = false): File

Creates the directory named by this abstract pathname.

Link copied to clipboard
@JvmOverloads
fun File.mkdirs2(mode: String?, mustCreate: Boolean = false): File

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories. In this event the implementation is such that it attempts to "clean up" any parent directories that it created, before throwing its exception.

Link copied to clipboard

Removes all . and resolves all possible .. for the provided path.

Link copied to clipboard

Opens a File for write operations, appending all new data to the end of the file.

Link copied to clipboard

Opens a File for read operations.

Link copied to clipboard

Opens a File for read/write operations. The File is not truncated if it already exists, and the initial FileStream.position is 0.

Link copied to clipboard

Opens a File for write operations. The File will be truncated if it exists.

fun File.openWrite(excl: OpenExcl?, appending: Boolean): FileStream.Write

Opens a File for write operations.

Link copied to clipboard

Reads the entire content of a file associated with the abstract pathname into a Buffer.

Link copied to clipboard
@JvmName(name = "readBytesFrom")
fun File.readBytes(): ByteArray

Read the entire contents of a File (as bytes).

Link copied to clipboard
@JvmName(name = "readUtf8From")
fun File.readUtf8(): String

Read the entire contents of a File (as UTF-8 text).

Link copied to clipboard
fun File.resolve(relative: File): File
fun File.resolve(relative: String): File

Resolves the File for provided relative. If relative is absolute, returns relative, otherwise will concatenate the File.paths.

Link copied to clipboard
inline operator fun Buffer.set(index: Number, value: Byte)

Helper for Buffer.writeInt8

Link copied to clipboard
fun File.stat(): Stats

Retrieve the Stats referred to by the abstract pathname.

Link copied to clipboard
@JvmName(name = "get")
inline fun String.toFile(): File

Syntactic Kotlin sugar.

Link copied to clipboard
fun Throwable.toIOException(): IOException
fun Throwable.toIOException(file: File?, other: File? = null): IOException

Converts the throwable to an IOException if it is not already one. When errorCodeOrNull is ENOENT, then this function will return FileNotFoundException. When the errorCodeOrNull is EINTR, then this function will return InterruptedIOException. When the errorCodeOrNull starts with ERR_FS_, then this function will return FileSystemException.

Link copied to clipboard
inline fun <T : Closeable?, R> T.use(block: (T) -> R): R

Executes the given block function on this resource and then closes it down correctly, whether an exception is thrown or not.

Link copied to clipboard
@JvmName(name = "wrapIO")
inline fun Throwable.wrapIOException(): IOException

Ensures that the throwable is an instance of IOException. If it is not, it will encase it in one. If the throwable is an instance of InterruptedException, this function returns an InterruptedIOException with the InterruptedException as a suppressed exception.

@JvmName(name = "wrapIO")
inline fun Throwable.wrapIOException(lazyMessage: () -> String): IOException

Ensures that the throwable is an instance of IOException. If it is not, it will encase it in one with the provided lazyMessage. If the throwable is an instance of InterruptedException, this function returns an InterruptedIOException with the InterruptedException as a suppressed exception.

Link copied to clipboard
inline fun File.write(excl: OpenExcl?, data: Buffer)

Writes the contents of a Buffer to the file associated with the abstract pathname. The File will be truncated if it exists.

fun File.write(excl: OpenExcl?, appending: Boolean, data: Buffer)

Writes the contents of a Buffer to the file associated with the abstract pathname.

Link copied to clipboard
@JvmName(name = "writeBytesTo")
inline fun File.writeBytes(excl: OpenExcl?, array: ByteArray): File

Writes the full contents of array to the file. The File will be truncated if it exists.

@JvmName(name = "writeBytesTo")
fun File.writeBytes(excl: OpenExcl?, appending: Boolean, array: ByteArray): File

Writes the full contents of array to the file.

Link copied to clipboard
@JvmName(name = "writeUtf8To")
inline fun File.writeUtf8(excl: OpenExcl?, text: String): File

Writes the full contents of text to the file (as UTF-8). The File will be truncated if it exists.

@JvmName(name = "writeUtf8To")
fun File.writeUtf8(excl: OpenExcl?, appending: Boolean, text: String): File

Writes the full contents of text to the file (as UTF-8).