FileChunks
Wrapper around NIOFileSystem.FileChunks
. This can be removed once NIOFileSystem
reaches a stable API.
struct FileChunks
Wrapper around NIOFileSystem.FileChunks
. This can be removed once NIOFileSystem
reaches a stable API.
struct FileChunks
import Vapor
Vapor is a framework for building server applications, APIs and websites in Swift. It provides a safe, performant and scalable foundation for building large complex backends.
struct FileIO
FileIO
is a convenience wrapper around SwiftNIO’s NonBlockingFileIO
.
func asyncStreamFile(at path: String, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, mediaType: HTTPMediaType? = nil, advancedETagComparison: Bool = false, onCompleted: @escaping (Result<Void, Error>) async throws -> () = { _ in }) async throws -> Response
Generates a chunked Response
for the specified file. This method respects values in the "ETag"
header and is capable of responding 304 Not Modified
if the file in question has not been modified since last served. If advancedETagComparison
is set to true, the response will have its ETag field set to a byte-by-byte hash of the requested file. If set to false, a simple ETag consisting of the last modified date and file size will be used. This method will also set the "Content-Type"
header automatically if an appropriate MediaType
can be found for the file’s suffix.
func collectFile(at path: String) async throws -> ByteBuffer
Reads the contents of a file at the supplied path.
func readFile(at path: String, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, offset: Int64? = nil, byteCount: Int? = nil) async throws -> FileChunks
Reads the contents of a file at the supplied path in chunks.
func streamFile(at path: String, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, mediaType: HTTPMediaType? = nil, advancedETagComparison: Bool, onCompleted: @escaping (Result<Void, Error>) -> () = { _ in }) -> EventLoopFuture<Response>
Generates a chunked Response
for the specified file. This method respects values in the "ETag"
header and is capable of responding 304 Not Modified
if the file in question has not been modified since last served. If advancedETagComparison
is set to true, the response will have its ETag field set to a byte-by-byte hash of the requested file. If set to false, a simple ETag consisting of the last modified date and file size will be used. This method will also set the "Content-Type"
header automatically if an appropriate MediaType
can be found for the file’s suffix.
func writeFile(_ buffer: ByteBuffer, at path: String) async throws
Write the contents of buffer to a file at the supplied path.
func collectFile(at path: String) -> EventLoopFuture<ByteBuffer>
Reads the contents of a file at the supplied path.
@preconcurrency func readFile(at path: String, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, onRead: @escaping (ByteBuffer) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>
Reads the contents of a file at the supplied path in chunks.
@preconcurrency func streamFile(at path: String, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, mediaType: HTTPMediaType? = nil, onCompleted: @escaping (Result<Void, Error>) -> () = { _ in }) -> Response
Generates a chunked Response
for the specified file. This method respects values in the "ETag"
header and is capable of responding 304 Not Modified
if the file in question has not been modified since last served. This method will also set the "Content-Type"
header automatically if an appropriate MediaType
can be found for the file’s suffix.
func writeFile(_ buffer: ByteBuffer, at path: String) -> EventLoopFuture<Void>
Write the contents of buffer to a file at the supplied path.
protocol AsyncSequence<Element, Failure>
A type that provides asynchronous, sequential, iterated access to its elements.
func closeHandle() async throws
func makeAsyncIterator() -> FileChunksIterator
struct FileChunksIterator
typealias Element = ByteBuffer
func allSatisfy(_ predicate: (Self.Element) async throws -> Bool) async rethrows -> Bool
Returns a Boolean value that indicates whether all elements produced by the asynchronous sequence satisfy the given predicate.
func collect(upTo maxBytes: Int) async throws -> ByteBuffer
Accumulates an AsyncSequence
of ByteBuffer
s into a single ByteBuffer
.
func collect(upTo maxBytes: Int, into accumulationBuffer: inout ByteBuffer) async throws
Accumulates an AsyncSequence
of ByteBuffer
s into a single accumulationBuffer
.
@preconcurrency func compactMap<ElementOfResult>(_ transform: @escaping (Self.Element) async -> ElementOfResult?) -> AsyncCompactMapSequence<Self, ElementOfResult>
Creates an asynchronous sequence that maps the given closure over the asynchronous sequence’s elements, omitting results that don’t return a value.
@preconcurrency func compactMap<ElementOfResult>(_ transform: @escaping (Self.Element) async throws -> ElementOfResult?) -> AsyncThrowingCompactMapSequence<Self, ElementOfResult>
Creates an asynchronous sequence that maps an error-throwing closure over the base sequence’s elements, omitting results that don’t return a value.
func contains(_ search: Self.Element) async rethrows -> Bool
Returns a Boolean value that indicates whether the asynchronous sequence contains the given element.
func contains(where predicate: (Self.Element) async throws -> Bool) async rethrows -> Bool
Returns a Boolean value that indicates whether the asynchronous sequence contains an element that satisfies the given predicate.
@preconcurrency func drop(while predicate: @escaping (Self.Element) async -> Bool) -> AsyncDropWhileSequence<Self>
Omits elements from the base asynchronous sequence until a given closure returns false, after which it passes through all remaining elements.
func dropFirst(_ count: Int = 1) -> AsyncDropFirstSequence<Self>
Omits a specified number of elements from the base asynchronous sequence, then passes through all remaining elements.
@preconcurrency func filter(_ isIncluded: @escaping (Self.Element) async -> Bool) -> AsyncFilterSequence<Self>
Creates an asynchronous sequence that contains, in order, the elements of the base sequence that satisfy the given predicate.
func first(where predicate: (Self.Element) async throws -> Bool) async rethrows -> Self.Element?
Returns the first element of the sequence that satisfies the given predicate.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async throws -> SegmentOfResult) -> AsyncThrowingFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence
Creates an asynchronous sequence that concatenates the results of calling the given error-throwing transformation with each element of this sequence.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async -> SegmentOfResult) -> AsyncFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence, Self.Failure == SegmentOfResult.Failure
Creates an asynchronous sequence that concatenates the results of calling the given transformation with each element of this sequence.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async -> SegmentOfResult) -> AsyncFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence, SegmentOfResult.Failure == Never
Creates an asynchronous sequence that concatenates the results of calling the given transformation with each element of this sequence.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async -> SegmentOfResult) -> AsyncFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence, Self.Failure == Never, SegmentOfResult.Failure == Never
Creates an asynchronous sequence that concatenates the results of calling the given transformation with each element of this sequence.
@preconcurrency func map<Transformed>(_ transform: @escaping (Self.Element) async -> Transformed) -> AsyncMapSequence<Self, Transformed>
Creates an asynchronous sequence that maps the given closure over the asynchronous sequence’s elements.
@preconcurrency func map<Transformed>(_ transform: @escaping (Self.Element) async throws -> Transformed) -> AsyncThrowingMapSequence<Self, Transformed>
Creates an asynchronous sequence that maps the given error-throwing closure over the asynchronous sequence’s elements.
@warn_unqualified_access func max(by areInIncreasingOrder: (Self.Element, Self.Element) async throws -> Bool) async rethrows -> Self.Element?
Returns the maximum element in the asynchronous sequence, using the given predicate as the comparison between elements.
@warn_unqualified_access func min(by areInIncreasingOrder: (Self.Element, Self.Element) async throws -> Bool) async rethrows -> Self.Element?
Returns the minimum element in the asynchronous sequence, using the given predicate as the comparison between elements.
func prefix(_ count: Int) -> AsyncPrefixSequence<Self>
Returns an asynchronous sequence, up to the specified maximum length, containing the initial elements of the base asynchronous sequence.
@preconcurrency func prefix(while predicate: @escaping (Self.Element) async -> Bool) rethrows -> AsyncPrefixWhileSequence<Self>
Returns an asynchronous sequence, containing the initial, consecutive elements of the base sequence that satisfy the given predicate.
func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Self.Element) async throws -> Result) async rethrows -> Result
Returns the result of combining the elements of the asynchronous sequence using the given closure.
func reduce<Result>(into initialResult: Result, _ updateAccumulatingResult: (inout Result, Self.Element) async throws -> Void) async rethrows -> Result
Returns the result of combining the elements of the asynchronous sequence using the given closure, given a mutable initial value.