p-x9/swift-fileio
A Swift library for reading and writing files.
Features
- MemoryMappedFile: using mmap
- StreamedFile: using FileHandle (syscall)
- ConcatenatedMemoryMappedFile: using mmap. Treats multiple files as one continuous virtual file.
- StreamedFile: using FileHandle (syscall). Treats multiple files as one continuous virtual file.
Usage
MemoryMappedFile/StreamedFile have the same API available for both.
Available methods are defined in the FileIOProtocol
Design Overview
This library separates file I/O into three orthogonal concerns:
- Capability: what operations are supported (
_FileIOProtocol) - Role: how the object is used (
FileIOProtocol,FileIOSiliceProtocol) - Implementation strategy: how I/O is performed (memory-mapped or streamed)
Protocol Relationships
The following diagram illustrates the relationships between the core protocols in this library.
graph TD
_FileIOProtocol --> FileIOProtocol
_FileIOProtocol --> FileIOSiliceProtocol
_FileIOProtocol --> _MemoryMappedFileIOProtocol
_FileIOProtocol --> _StreamedFileIOProtocol
FileIOProtocol --> MemoryMappedFileIOProtocol
FileIOProtocol --> StreamedFileIOProtocol
_MemoryMappedFileIOProtocol --> MemoryMappedFileIOProtocol
_StreamedFileIOProtocol --> StreamedFileIOProtocol
FileIOProtocol --> FileSlice[associatedtype FileSlice]
FileSlice --> FileIOSiliceProtocol
_FileIOProtocol --> ResizableFileIOProtocol_FileIOProtocoldefines the fundamental read/write and synchronization operations.FileIOProtocolextends it with file-opening and slicing capabilities.FileIOSiliceProtocolrepresents a logical view into a file with abaseOffset.ResizableFileIOProtocoladds structural mutation operations such as insert and delete._MemoryMappedFileIOProtocoland_StreamedFileIOProtocoldescribe low-level implementation traits.MemoryMappedFileIOProtocolandStreamedFileIOProtocolcombine implementation traits withFileIOProtocol.
License
FileIO is released under the MIT License. See LICENSE
Package Metadata
Repository: p-x9/swift-fileio
Default branch: main
README: README.md