mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
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:
1 parent
b881f6ec60
commit
8997a24524
20 files changed
+1387
-191
No files matched your search
@@ -25,7 +25,7 @@ extension String {
|
||||
///
|
||||
/// - Throws: If the file is larger than `maximumSizeAllowed`, an ``FileSystemError/Code-swift.struct/resourceExhausted`` error will be thrown.
|
||||
public init(
|
||||
contentsOf path: FilePath,
|
||||
contentsOf path: NIOFilePath,
|
||||
maximumSizeAllowed: ByteCount,
|
||||
fileSystem: some FileSystemProtocol
|
||||
) async throws {
|
||||
@@ -36,6 +36,23 @@ extension String {
|
||||
self = Self(buffer: byteBuffer)
|
||||
}
|
||||
|
||||
/// Reads the contents of the file at the path into a String.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - path: The path of the file to read.
|
||||
/// - maximumSizeAllowed: The maximum size of file which can be read, in bytes, as a ``ByteCount``. If the file is larger than this, an error is thrown.
|
||||
/// - fileSystem: The ``FileSystemProtocol`` instance to use to read the file.
|
||||
///
|
||||
/// - Throws: If the file is larger than `maximumSizeAllowed`, an ``FileSystemError/Code-swift.struct/resourceExhausted`` error will be thrown.
|
||||
@_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:
|
||||
@@ -44,7 +61,7 @@ extension String {
|
||||
///
|
||||
/// - Throws: If the file is larger than `maximumSizeAllowed`, an ``FileSystemError/Code-swift.struct/resourceExhausted`` error will be thrown.
|
||||
public init(
|
||||
contentsOf path: FilePath,
|
||||
contentsOf path: NIOFilePath,
|
||||
maximumSizeAllowed: ByteCount
|
||||
) async throws {
|
||||
self = try await Self(
|
||||
@@ -53,4 +70,19 @@ extension String {
|
||||
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, in bytes, as a ``ByteCount``. If the file is larger than this, an error is thrown.
|
||||
///
|
||||
/// - Throws: If the file is larger than `maximumSizeAllowed`, an ``FileSystemError/Code-swift.struct/resourceExhausted`` error will be thrown.
|
||||
@_disfavoredOverload
|
||||
public init(
|
||||
contentsOf path: FilePath,
|
||||
maximumSizeAllowed: ByteCount
|
||||
) async throws {
|
||||
try await self.init(contentsOf: .init(path), maximumSizeAllowed: maximumSizeAllowed)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user