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
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// This source file is part of the SwiftNIO open source project
|
||||
//
|
||||
// Copyright (c) 2023 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
|
||||
@@ -23,7 +23,7 @@ extension ByteBuffer {
|
||||
/// - 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 {
|
||||
@@ -35,13 +35,28 @@ extension 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(
|
||||
@@ -51,6 +66,19 @@ extension ByteBuffer {
|
||||
)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
/// Writes the readable bytes of the ``ByteBuffer`` to a file.
|
||||
///
|
||||
/// - Parameters:
|
||||
@@ -61,7 +89,7 @@ extension ByteBuffer {
|
||||
/// - Returns: The number of bytes written to the file.
|
||||
@discardableResult
|
||||
public func write(
|
||||
toFileAt path: FilePath,
|
||||
toFileAt path: NIOFilePath,
|
||||
absoluteOffset offset: Int64 = 0,
|
||||
options: OpenOptions.Write = .newFile(replaceExisting: false),
|
||||
fileSystem: some FileSystemProtocol
|
||||
@@ -80,11 +108,30 @@ extension ByteBuffer {
|
||||
/// - path: The path of the file to write the contents of the sequence to.
|
||||
/// - offset: The offset into the file to write to, defaults to zero.
|
||||
/// - options: Options for opening the file, defaults to creating a new file.
|
||||
/// - fileSystem: The ``FileSystemProtocol`` instance to use.
|
||||
/// - Returns: The number of bytes written to the file.
|
||||
@_disfavoredOverload
|
||||
@discardableResult
|
||||
public func write(
|
||||
toFileAt path: FilePath,
|
||||
absoluteOffset offset: Int64 = 0,
|
||||
options: OpenOptions.Write = .newFile(replaceExisting: false),
|
||||
fileSystem: some FileSystemProtocol
|
||||
) async throws -> Int64 {
|
||||
try await self.write(toFileAt: .init(path), absoluteOffset: offset, options: options, fileSystem: fileSystem)
|
||||
}
|
||||
|
||||
/// Writes the readable bytes of the ``ByteBuffer`` to a file.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - path: The path of the file to write the contents of the sequence to.
|
||||
/// - offset: The offset into the file to write to, defaults to zero.
|
||||
/// - options: Options for opening the file, defaults to creating a new file.
|
||||
/// - Returns: The number of bytes written to the file.
|
||||
@discardableResult
|
||||
public func write(
|
||||
toFileAt path: NIOFilePath,
|
||||
absoluteOffset offset: Int64 = 0,
|
||||
options: OpenOptions.Write = .newFile(replaceExisting: false)
|
||||
) async throws -> Int64 {
|
||||
try await self.write(
|
||||
@@ -94,4 +141,21 @@ extension ByteBuffer {
|
||||
fileSystem: .shared
|
||||
)
|
||||
}
|
||||
|
||||
/// Writes the readable bytes of the ``ByteBuffer`` to a file.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - path: The path of the file to write the contents of the sequence to.
|
||||
/// - offset: The offset into the file to write to, defaults to zero.
|
||||
/// - options: Options for opening the file, defaults to creating a new file.
|
||||
/// - Returns: The number of bytes written to the file.
|
||||
@_disfavoredOverload
|
||||
@discardableResult
|
||||
public func write(
|
||||
toFileAt path: FilePath,
|
||||
absoluteOffset offset: Int64 = 0,
|
||||
options: OpenOptions.Write = .newFile(replaceExisting: false)
|
||||
) async throws -> Int64 {
|
||||
try await self.write(toFileAt: .init(path), absoluteOffset: offset, options: options)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user