Update FilePath references to NIOFilePath (#3333)

Motivation:

Currently, file paths are represented by the `SystemPackage.FilePath`
type in `NIOFileSystem`. Following from #3322, we want to use
`NIOFilePath` instead.

Modifications:

This change provides `NIOFilePath` accepting/returning variants to all
existing public methods that accept/return `SystemPackage.FilePath`.

The bulk of the changes are in `FileSystemProtocol` and
`FileHandleProtocol`, and their conforming types. The protocols have
been modified to require `NIOFilePath` accepting/returning methods.
Default implementations are provided for `SystemPackage.FilePath`
accepting/returning methods---these call through to the `NIOFilePath`
variants.

Result:

`NIOFilePath` path representations can now be used with the methods for
interacting with the file system.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
This commit is contained in:
aryan-25andGeorge Barnett authored and GitHub committed 2025-08-11 17:29:02 +01:00
1 parent b881f6ec60
commit 8997a24524
20 files changed
+1387 -191

No files matched your search

@@ -2,7 +2,7 @@
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
// Copyright (c) 2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
@@ -27,7 +27,7 @@ extension Data {
/// - maximumSizeAllowed: The maximum size of file which can be read, in bytes, as a ``ByteCount``.
/// - fileSystem: The ``FileSystemProtocol`` instance to use to read the file.
public init(
contentsOf path: FilePath,
contentsOf path: NIOFilePath,
maximumSizeAllowed: ByteCount,
fileSystem: some FileSystemProtocol
) async throws {
@@ -38,13 +38,28 @@ extension Data {
self = Data(buffer: byteBuffer)
}
/// Reads the contents of the file at the path.
///
/// - Parameters:
/// - path: The path of the file to read.
/// - maximumSizeAllowed: The maximum size of file which can be read, in bytes, as a ``ByteCount``.
/// - fileSystem: The ``FileSystemProtocol`` instance to use to read the file.
@_disfavoredOverload
public init(
contentsOf path: FilePath,
maximumSizeAllowed: ByteCount,
fileSystem: some FileSystemProtocol
) async throws {
try await self.init(contentsOf: .init(path), maximumSizeAllowed: maximumSizeAllowed, fileSystem: fileSystem)
}
/// Reads the contents of the file at the path using ``FileSystem``.
///
/// - Parameters:
/// - path: The path of the file to read.
/// - maximumSizeAllowed: The maximum size of file which can be read, as a ``ByteCount``.
public init(
contentsOf path: FilePath,
contentsOf path: NIOFilePath,
maximumSizeAllowed: ByteCount
) async throws {
self = try await Self(
@@ -53,5 +68,18 @@ extension Data {
fileSystem: .shared
)
}
/// Reads the contents of the file at the path using ``FileSystem``.
///
/// - Parameters:
/// - path: The path of the file to read.
/// - maximumSizeAllowed: The maximum size of file which can be read, as a ``ByteCount``.
@_disfavoredOverload
public init(
contentsOf path: FilePath,
maximumSizeAllowed: ByteCount
) async throws {
try await self.init(contentsOf: .init(path), maximumSizeAllowed: maximumSizeAllowed)
}
}
#endif