Contents

read(fromAbsoluteOffset:into:retryOnInterrupt:)

Reads bytes at the specified offset into a buffer.

Declaration

func read(fromAbsoluteOffset offset: Int64, into buffer: UnsafeMutableRawBufferPointer, retryOnInterrupt: Bool = true) throws -> Int

Parameters

  • offset:

    The file offset where reading begins.

  • buffer:

    The region of memory to read into.

  • retryOnInterrupt:

    Whether to retry the read operation if it throws Interrupted. The default is true. Pass false to try only once and throw an error upon interruption.

Mentioned in

Return Value

The number of bytes that were read.

Discussion

The doc://com.apple.documentation/documentation/swift/unsafemutablerawbufferpointer/count-95usp property of buffer determines the maximum number of bytes that are read into that buffer.

Unlike read(into:retryOnInterrupt:), this method leaves the file’s existing offset unchanged.

The corresponding C function is pread.

See Also

Reading From a File