Files
Rick Newton-Rogers 41f66948e1 fix link to NIOFileSystem from NIO index page (#2747)
Motivation:

The existing link to NIOFileSystem docs 404's

Modifications:

Speculative fixes because getting any links to work locally is
challenging.

* rename `NIOFileSystem.md` -> `index.md` in line with other modules
* modify the link on the NIO index page to reference `_NIOFileSystem`
  local experiments suggest it might change the form of the generated
URL to where the docs can be found
(https://swiftpackageindex.com/apple/swift-nio/2.67.0/documentation/_NIOFileSystem).

Result:

Hopefully the NIOFileSystem docs link will work
2024-06-21 16:59:46 +01:00

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 FileInfo for further details.

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

  • FileSystem
  • FileHandle
  • ReadFileHandle
  • WriteFileHandle
  • ReadWriteFileHandle
  • DirectoryFileHandle
  • withFileSystem(numberOfThreads:_:)

File and Directory Information

  • FileInfo
  • FileType

Reading Files

  • FileChunks
  • BufferedReader

Writing Files

  • BufferedWriter

Listing Directories

  • DirectoryEntry
  • DirectoryEntries

Errors

FileSystemError is the only top-level error type thrown by the package (apart from Swift's CancellationError).

  • FileSystemError
  • FileSystemError/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:

  • FileSystemProtocol
  • FileHandleProtocol
  • ReadableFileHandleProtocol
  • WritableFileHandleProtocol
  • ReadableAndWritableFileHandleProtocol
  • DirectoryFileHandleProtocol