Skip to content

Commit

Permalink
Migrate new API to use NIOFileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim committed Apr 24, 2024
1 parent f2c439a commit 863207d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions Sources/Vapor/Utilities/FileIO.swift
Expand Up @@ -304,13 +304,10 @@ public struct FileIO: Sendable {
/// - path: Path to file on the disk.
/// - returns: `ByteBuffer` containing the file data.
public func collectFile(at path: String) async throws -> ByteBuffer {
guard
let attributes = try? FileManager.default.attributesOfItem(atPath: path),
let fileSize = attributes[.size] as? NSNumber
else {
guard let fileSize = try await FileSystem.shared.info(forFileAt: .init(path))?.size else {
throw Abort(.internalServerError)
}
return try await self.read(path: path, fromOffset: 0, byteCount: fileSize.intValue)
return try await self.read(path: path, fromOffset: 0, byteCount: Int(fileSize))
}

/// Wrapper around `NIOFileSystem.FileChunks`.
Expand Down
2 changes: 1 addition & 1 deletion Tests/VaporTests/FileTests.swift
Expand Up @@ -486,7 +486,7 @@ final class FileTests: XCTestCase {
}

func testAsyncFileRead() async throws {
let app = Application(.testing)
let app = await Application(.testing)
defer { app.shutdown() }

let request = Request(application: app, on: app.eventLoopGroup.next())
Expand Down

0 comments on commit 863207d

Please sign in to comment.