Error
NonBlockingFileIO
errors.
enum Error
NonBlockingFileIO
errors.
enum Error
import NIOPosix
struct NonBlockingFileIO
NonBlockingFileIO
is a helper that allows you to read files without blocking the calling thread.
case descriptorSetToNonBlocking
NonBlockingFileIO
is meant to be used with file descriptors that are set to the default (blocking) mode. It doesn’t make sense to use it with a file descriptor where O_NONBLOCK
is set therefore this error is raised when that was requested.
init(threadPool: NIOThreadPool)
Initialize a NonBlockingFileIO
which uses the NIOThreadPool
.
static let defaultChunkSize: Int
The default and recommended chunk size.
static let defaultThreadPoolSize: Int
The default and recommended size for NonBlockingFileIO
’s thread pool.
func changeFileSize(fileHandle: NIOFileHandle, size: Int64) async throws
Changes the file size of fileHandle
to size
.
func changeFileSize(fileHandle: NIOFileHandle, size: Int64, eventLoop: EventLoop) -> EventLoopFuture<()>
Changes the file size of fileHandle
to size
.
func createDirectory(path: String, withIntermediateDirectories createIntermediates: Bool = false, mode: NIOPOSIXFileMode) async throws
Creates directory at path
on a private thread pool.
func createDirectory(path: String, withIntermediateDirectories createIntermediates: Bool = false, mode: NIOPOSIXFileMode, eventLoop: EventLoop) -> EventLoopFuture<Void>
Creates directory at path
on a private thread pool which is separate from any EventLoop
thread.
func listDirectory(path: String) async throws -> [NIODirectoryEntry]
List contents of the directory at path
on a private thread pool.
func listDirectory(path: String, eventLoop: EventLoop) -> EventLoopFuture<[NIODirectoryEntry]>
List contents of the directory at path
on a private thread pool which is separate from any EventLoop
thread.
func lstat(path: String) async throws -> stat
Returns information about a file at path
on a private thread pool.
func lstat(path: String, eventLoop: EventLoop) -> EventLoopFuture<stat>
Returns information about a file at path
on a private thread pool which is separate from any EventLoop
thread.
func openFile(_deprecatedPath path: String, eventLoop: EventLoop) -> EventLoopFuture<(NIOFileHandle, FileRegion)>
Open the file at path
for reading on a private thread pool which is separate from any EventLoop
thread.
func openFile(_deprecatedPath path: String, mode: NIOFileHandle.Mode, flags: NIOFileHandle.Flags = .default, eventLoop: EventLoop) -> EventLoopFuture<NIOFileHandle>
Open the file at path
with specified access mode and POSIX flags on a private thread pool which is separate from any EventLoop
thread.
func read(fileHandle: NIOFileHandle, byteCount: Int, allocator: ByteBufferAllocator) async throws -> ByteBuffer
Read byteCount
bytes from fileHandle
in NonBlockingFileIO
’s private thread pool.
func read(fileHandle: NIOFileHandle, byteCount: Int, allocator: ByteBufferAllocator, eventLoop: EventLoop) -> EventLoopFuture<ByteBuffer>
Read byteCount
bytes from fileHandle
in NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
func read(fileHandle: NIOFileHandle, fromOffset fileOffset: Int64, byteCount: Int, allocator: ByteBufferAllocator) async throws -> ByteBuffer
Read byteCount
bytes starting at fileOffset
from fileHandle
in NonBlockingFileIO
’s private thread pool .
func read(fileHandle: NIOFileHandle, fromOffset fileOffset: Int64, byteCount: Int, allocator: ByteBufferAllocator, eventLoop: EventLoop) -> EventLoopFuture<ByteBuffer>
Read byteCount
bytes starting at fileOffset
from fileHandle
in NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
func read(fileRegion: FileRegion, allocator: ByteBufferAllocator) async throws -> ByteBuffer
Read a FileRegion
in NonBlockingFileIO
’s private thread pool.
func read(fileRegion: FileRegion, allocator: ByteBufferAllocator, eventLoop: EventLoop) -> EventLoopFuture<ByteBuffer>
Read a FileRegion
in NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
@preconcurrency func readChunked(fileHandle: NIOFileHandle, byteCount: Int, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, allocator: ByteBufferAllocator, eventLoop: EventLoop, chunkHandler: @escaping (ByteBuffer) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>
Read byteCount
bytes in chunks of chunkSize
bytes from fileHandle
in NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
@preconcurrency func readChunked(fileHandle: NIOFileHandle, fromOffset fileOffset: Int64, byteCount: Int, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, allocator: ByteBufferAllocator, eventLoop: EventLoop, chunkHandler: @escaping (ByteBuffer) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>
Read byteCount
bytes from offset fileOffset
in chunks of chunkSize
bytes from fileHandle
in NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
@preconcurrency func readChunked(fileRegion: FileRegion, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, allocator: ByteBufferAllocator, eventLoop: EventLoop, chunkHandler: @escaping (ByteBuffer) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>
Read a FileRegion
in chunks of chunkSize
bytes on NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
func readFileSize(fileHandle: NIOFileHandle) async throws -> Int64
Returns the length of the file associated with fileHandle
.
func readFileSize(fileHandle: NIOFileHandle, eventLoop: EventLoop) -> EventLoopFuture<Int64>
Returns the length of the file in bytes associated with fileHandle
.
func readlink(path: String) async throws -> String
Returns target of the symbolic link at path
on a private thread pool.
func readlink(path: String, eventLoop: EventLoop) -> EventLoopFuture<String>
Returns target of the symbolic link at path
on a private thread pool which is separate from any EventLoop
thread.
func remove(path: String) async throws
Removes the file at path
on a private thread pool.
func remove(path: String, eventLoop: EventLoop) -> EventLoopFuture<Void>
Removes the file at path
on a private thread pool which is separate from any EventLoop
thread.
func rename(path: String, newName: String) async throws
Renames the file at path
to newName
on a private thread pool.
func rename(path: String, newName: String, eventLoop: EventLoop) -> EventLoopFuture<Void>
Renames the file at path
to newName
on a private thread pool which is separate from any EventLoop
thread.
func symlink(path: String, to destination: String) async throws
Creates a symbolic link to a destination
file at path
on a private thread pool.
func symlink(path: String, to destination: String, eventLoop: EventLoop) -> EventLoopFuture<Void>
Creates a symbolic link to a destination
file at path
on a private thread pool which is separate from any EventLoop
thread.
func unlink(path: String) async throws
Removes symbolic link at path
on a private thread pool which is separate from any EventLoop
thread.
func unlink(path: String, eventLoop: EventLoop) -> EventLoopFuture<Void>
Removes symbolic link at path
on a private thread pool which is separate from any EventLoop
thread.
func withFileHandle<Result>(_deprecatedPath path: String, mode: NIOFileHandle.Mode, flags: NIOFileHandle.Flags = .default, _ body: (NIOFileHandle) async throws -> Result) async throws -> Result
func withFileRegion<Result>(_deprecatedPath path: String, _ body: (_ fileRegion: FileRegion) async throws -> Result) async throws -> Result
func write(fileHandle: NIOFileHandle, buffer: ByteBuffer) async throws
Write buffer
to fileHandle
in NonBlockingFileIO
’s private thread pool.
func write(fileHandle: NIOFileHandle, buffer: ByteBuffer, eventLoop: EventLoop) -> EventLoopFuture<()>
Write buffer
to fileHandle
in NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
func write(fileHandle: NIOFileHandle, toOffset: Int64, buffer: ByteBuffer) async throws
Write buffer
starting from toOffset
to fileHandle
in NonBlockingFileIO
’s private thread pool.
func write(fileHandle: NIOFileHandle, toOffset: Int64, buffer: ByteBuffer, eventLoop: EventLoop) -> EventLoopFuture<()>
Write buffer
starting from toOffset
to fileHandle
in NonBlockingFileIO
’s private thread pool which is separate from any EventLoop
thread.
func openFile(path: String, eventLoop: EventLoop) -> EventLoopFuture<(NIOFileHandle, FileRegion)>
Open the file at path
for reading on a private thread pool which is separate from any EventLoop
thread.
func openFile(path: String, mode: NIOFileHandle.Mode, flags: NIOFileHandle.Flags = .default, eventLoop: EventLoop) -> EventLoopFuture<NIOFileHandle>
Open the file at path
with specified access mode and POSIX flags on a private thread pool which is separate from any EventLoop
thread.
func withFileHandle<Result>(path: String, mode: NIOFileHandle.Mode, flags: NIOFileHandle.Flags = .default, _ body: (NIOFileHandle) async throws -> Result) async throws -> Result
Open file at path
on a private thread pool, run an operation given the file handle and then close the file handle.
func withFileRegion<Result>(path: String, _ body: (_ fileRegion: FileRegion) async throws -> Result) async throws -> Result
Open file at path
and query its size on a private thread pool, run an operation given the resulting file region and then close the file handle.
protocol Equatable
A type that can be compared for value equality.
protocol Error : Sendable
A type representing an error value that can be thrown.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
import MongoKitten
var localizedDescription: String { get }
Retrieve the localized description for this error.