Motivation: We changed the file path type in `_NIOFileSystem` to use `NIOFilePath` instead of `FilePath`. Originally we planned to use API shims to avoid breaking API, however in some cases this was inevitable (i.e. where a file path is returned to the caller). To roll over to the new API we will instead introduce the `NIOFileSystem` module using `NIOFilePath` and have `_NIOFileSystem` use `FilePath`. Users can then opt-in to the new stable API rather than having it forced upon them. The first wave of these changes turns `_NIOFileSystem` into `NIOFileSystem` and uses `NIOFilePath` for its APIs. Modifications: - Remove disfavoured overloads (i.e. `FilePath` APIs) - Update the `DirectoryEntry` API to use `NIOFilePath`. - Update tests to use `NIOFilePath` since many were relying on the newly removed shims - Remove the underscore from the module names and products - Remove deprecated methods A follow up change will re-instate the `_NIOFileSystem` (and compat) module and products using `FilePath`. Result: `NIOFileSystem` has a stable API.
2.2 KiB
NIOFileSystem
A file system library for Swift.
Overview
This module implements a file system library for Swift, providing ways to interact with and manage
files. It provides a concrete FileSystem for interacting with the local file system in addition
to a set of protocols for creating other file system implementations.
NIOFileSystem is cross-platform with the following caveats:
- Platforms don't have feature parity or system-level API parity. Where this is the case these implementation details are documented. One example is copying files, on Apple platforms files are cloned if possible.
- Features may be disabled on some systems. One example is extended attributes.
- Some types have platform specific representations. These include the following:
- File paths on Apple platforms and Linux (e.g.
"/Users/hal9000/") are different to paths on Windows ("C:\Users\hal9000"). - Information about files is different on different platforms. See
FileInfofor further details.
- File paths on Apple platforms and Linux (e.g.
A Brief Tour
The following sample code demonstrates a number of the APIs offered by this module:
@Snippet(path: "swift-nio/Snippets/NIOFileSystemTour")
In depth documentation can be found in the following sections.
Topics
Interacting with the Local File System
FileSystemFileHandleReadFileHandleWriteFileHandleReadWriteFileHandleDirectoryFileHandlewithFileSystem(numberOfThreads:_:)
File and Directory Information
FileInfoFileType
Reading Files
FileChunksBufferedReader
Writing Files
BufferedWriter
Listing Directories
DirectoryEntryDirectoryEntries
Errors
FileSystemError is the only top-level error type thrown by the package (apart from Swift's
CancellationError).
FileSystemErrorFileSystemError/SystemCallError
Creating a File System
Custom file system's can be created by implementing FileSystemProtocol which depends on a number
of other protocols. These include the following:
FileSystemProtocolFileHandleProtocolReadableFileHandleProtocolWritableFileHandleProtocolReadableAndWritableFileHandleProtocolDirectoryFileHandleProtocol