Skip to content

Commit

Permalink
Update Sources/Vapor/Utilities/FileIO.swift
Browse files Browse the repository at this point in the history
Co-authored-by: Gwynne Raskind <gwynne@vapor.codes>
  • Loading branch information
0xTim and gwynne committed May 7, 2024
1 parent b134912 commit 0d6b4f4
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Sources/Vapor/Utilities/FileIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,18 @@ public struct FileIO: Sendable {
chunkSize: Int = NonBlockingFileIO.defaultChunkSize,
onRead: @Sendable @escaping (ByteBuffer) -> EventLoopFuture<Void>
) -> EventLoopFuture<Void> {
return self.request.eventLoop.makeFutureWithTask { () -> Int64? in
let fileInfo = try await FileSystem.shared.info(forFileAt: .init(path))
return fileInfo?.size
}.flatMap { fileSize in
guard let fileSize = fileSize else {
return self.request.eventLoop.makeFailedFuture(Abort(.internalServerError))
self.request.eventLoop.makeFutureWithTask {
guard let fileSize = try await FileSystem.shared.info(forFileAt: .init(path))?.size else {
throw Abort(.internalServerError)
}
return self.read(
try await self.read(
path: path,
fromOffset: 0,
byteCount: Int(fileSize),
chunkSize: chunkSize,
onRead: onRead
)
).get()
}
}
}

Expand Down

0 comments on commit 0d6b4f4

Please sign in to comment.