Protocolswift-nio 2.72.0_NIOFileSystem
ReadableFileHandleProtocol
A handle for reading data from an open file.
FileHandleProtocol.swift:185ReadableFileHandleProtocol.md- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
protocol ReadableFileHandleProtocol : FileHandleProtocol
ReadableFileHandleProtocol
refines FileHandleProtocol
to add requirements for reading data from a file.
There are two requirements for implementing this protocol:
``readChunks(chunkLength:)
A number of overloads are provided which provide sensible defaults.
Conformance to ReadableFileHandleProtocol
also provides readToEnd(fromAbsoluteOffset:maximumSizeAllowed:)
(and various overloads with sensible defaults) for reading the contents of a file into memory.
Read the contents of a file
func bufferedReader(startingAtAbsoluteOffset: Int64, capacity: ByteCount
) -> BufferedReader<Self> Creates a new
BufferedReader
for this file handle.func readChunks(chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
func readChunks(in: Range<Int64>, chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
func readChunks(in: UnboundedRange, chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
func readChunks(in: ClosedRange<Int64>, chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
func readChunks(in: PartialRangeFrom<Int64>, chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
func readChunks(in: PartialRangeThrough<Int64>, chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
func readChunks(in: PartialRangeUpTo<Int64>, chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
func readToEnd(fromAbsoluteOffset: Int64, maximumSizeAllowed: ByteCount
) async throws -> ByteBuffer Returns the contents of a file by loading it into memory.
Read part of a file
func readChunk(fromAbsoluteOffset: Int64, length: ByteCount
) async throws -> ByteBuffer Returns a slice of bytes read from the file.
Requirements
Instance members
func readChunks(in: Range<Int64>, chunkLength: ByteCount
) -> FileChunks Returns an asynchronous sequence of chunks read from the file.
See also
protocol FileSystemProtocol
The interface for interacting with a file system.
protocol FileHandleProtocol
A handle for a file system object.
protocol WritableFileHandleProtocol
A file handle suitable for writing.
typealias ReadableAndWritableFileHandleProtocol
A file handle which is suitable for reading and writing.
protocol DirectoryFileHandleProtocol
A handle suitable for directories.