FileRegion

public struct FileRegion

A FileRegion represent a readable portion usually created to be sent over the network.

Usually a FileRegion will allow the underlying transport to use sendfile to transfer its content and so allows transferring the file content without copying it into user-space at all. If the actual transport implementation really can make use of sendfile or if it will need to copy the content to user-space first and use write / writev is an implementation detail. That said using FileRegion is the recommended way to transfer file content if possible.

One important note, depending your ChannelPipeline setup it may not be possible to use a FileRegion as a ChannelHandler may need access to the bytes (in a ByteBuffer) to transform these.

Note

It is important to manually manage the lifetime of the FileHandle used to create a FileRegion.
  • The FileHandle that is used by this FileRegion.

    Declaration

    Swift

    public let fileHandle: FileHandle
  • The current reader index of this FileRegion

    Declaration

    Swift

    private(set) public var readerIndex: Int { get set }
  • The end index of this FileRegion.

    Declaration

    Swift

    public var endIndex: Int { get }
  • Create a new FileRegion from an open FileHandle.

    Declaration

    Swift

    public init(fileHandle: FileHandle, readerIndex: Int, endIndex: Int)

    Parameters

    fileHandle

    the FileHandle to use.

    readerIndex

    the index (offset) on which the reading will start.

    endIndex

    the index which represent the end of the readable portion.

  • The number of readable bytes within this FileRegion (taking the readerIndex and endIndex into account).

    Declaration

    Swift

    public var readableBytes: Int { get }
  • Move the readerIndex forward by offset.

    Declaration

    Swift

    public mutating func moveReaderIndex(forwardBy offset: Int)
  • Declaration

    Swift

    public static func ==(lhs: FileRegion, rhs: FileRegion) -> Bool
  • Declaration

    Swift

    public var description: String { get }