File management and path analysis for Swift

Overview

Banner

Pathos offers cross-platform virtual file system APIs for Swift.

Pathos is implement from ground-up with on each OS's native API. It has zero dependencies.

Windows support is currently considered experimental.

Swift 5.3 & 5.3.1
Amazon Linux 2
CentOS 8
macOS 11.15
Ubuntu Bionic
Ubuntu Focal
Windows 2019 (Experimental)

For a taste of Pathos, let's generate a static site from Markdown!

import Pathos

// Set the CWD and execute a closure
try Path("markdown-source-dir").asWorkingDirectory {
    // Build the site in a unique, temporary directory
    let temporaryRoot = try Path.makeTemporaryDirectory()
    
    // Joining path components that works across OSes.
    // E.g. `articles/**/*.md` on POSIX systems.
    let pattern = Path("articles") + "**" + "*.md"
    
    // Use glob to find files that matches the pattern
    for markdown in try pattern.glob() {
        // path/to/file.md => path/to/file
        let url = markdown.base
        
        // path that contains index.html
        let htmlDirectory = temporaryRoot + url
        
        // make a directory, including multiple levels
        try htmlDirectory.makeDirectory(withParents: true)
        
        // read content of a file
        let source = try markdown.readUTF8String()
        
        // write out the html, imagine `markdown2html` exists
        try (htmlDirectory + "index.html").write(utf8: markdown2html(source))
    }

    // all done! move the built site to output directory
    try temporaryRoot.move(to: "output")
}
// CWD is restored after the closure is done

As you can see, Pathos offers a whole suite of APIs for inspecting and manipulating the file system. Programs built with Pathos compile and work on all supported OS without the need to use #if OS() in the source.

There are more Examples for the curious.

Installation

With SwiftPM

.package(url: "http://github.com/dduan/Pathos", from: "0.4.0")

Documentation

  1. User Guide - A tour of Pathos for introduction purposes.
  2. API Refererence - Complete reference to Pathos public APIs.
  3. Design - Answers for why an API is designed as such.
  4. Change Log - Change logs for all Pathos versions.

You may also checkout the Example apps.

License

Pathos is released under the MIT license. See LICENSE.md

You might also like...
🎹 MIDIKit extension for SMF (Standard MIDI File)

🔌 SMF (Standard MIDI File) Extension for MIDIKit This extension adds abstractions for reading and writing Standard MIDI Files. Getting Started Add MI

ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

SSZipArchive ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS. Unzip zip files; Unzip password protected zi

FileManager replacement for Local, iCloud and Remote (WebDAV/FTP/Dropbox/OneDrive) files -- Swift
FileManager replacement for Local, iCloud and Remote (WebDAV/FTP/Dropbox/OneDrive) files -- Swift

This Swift library provide a swifty way to deal with local and remote files and directories in a unified way. This library provides implementaion of W

Swift framework for zipping and unzipping files.
Swift framework for zipping and unzipping files.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Effortless ZIP Handling in Swift
Effortless ZIP Handling in Swift

ZIP Foundation is a library to create, read and modify ZIP archive files. It is written in Swift and based on Apple's libcompression for high performa

Swift framework to connect SMB2/3 shares

AMSMB2 This is small Swift library for iOS, macOS and tvOS which wraps libsmb2 and allows to connect a SMB2/3 share and do file operation. Install Coc

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri
Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri. This plugin is similar to cordova-plugin-file-opener2 without installation support.

FileKit is a Swift framework that allows for simple and expressive file management.
FileKit is a Swift framework that allows for simple and expressive file management.

FileKit is a Swift framework that allows for simple and expressive file management.

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind
Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

A static source code analysis tool to improve quality and reduce defects for C, C++ and Objective-C

OCLint - https://oclint.org OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR

OysterKit A Swift Framework for Tokenizing, Parsing, and Interpreting Languages OysterKit enables native Swift scanning, lexical analysis, and parsing

Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

AudioKit AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

AudioKit AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

A spatial analysis library written in Swift for native iOS, macOS, tvOS, watchOS, and Linux applications, ported from Turf.js.

Turf for Swift 📱 🖥 💻 📺 ⌚️ A spatial analysis library written in Swift for native iOS, macOS, tvOS, watchOS, and Linux applications, ported from Tu

Cloud Drive(GoogleDrive/Dropbox/BaiduPan/OneDrive/pCloud) File Management

CloudServiceKit Easy to integrate cloud service using Oauth2. Supported platforms: AliyunDrive BaiduPan Box Dropbox Google Drive OneDrive pCloud Requi

iOS hashtag generator, using image analysis and discovery
iOS hashtag generator, using image analysis and discovery

Tagger Description Want to be popular on some social network easily? Use Tagger to make your account content more popular and to raise your popularity

LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.
LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.

LinkedLog Xcode Plugin LinkedLog is a Xcode plugin that includes a Xcode PCH file template that adds the macros LLog and LLogF. The LLog macro will wo

Numerical Analysis of Fundamental Frequencies (NAFF)

hpNaff Numerical Analysis of Fundamental Frequencies (NAFF) A little command line tool (macOS, Linux, Windows1) to perform high-resolution frequency a

Comments
  • Add Carthage support

    Add Carthage support

    1. Use XcodeGen to generate a Xcode project. Note that SwiftPM is not good enough since we need a Info.plist and various configurations (via .xcconfig).
    2. Use Carthage's build --archive command to create the framework archive to go alone with releases.
    3. Both tools binary is checked-in in bin.
    opened by dduan 2
  • File extension API returns extension with period

    File extension API returns extension with period

    Not sure if there's some standard around this that I'm missing, but I would expect fileExtension(ofPath: "myFile.swift") to return swift and not .swift. To me, the period is the separator between file name and extension and not part of the extension itself.

    opened by sberrevoets 1
  • Not all public interfaces links to their counterparts

    Not all public interfaces links to their counterparts

    Every free function has a counter part as PathRepresentable method. In the documentation they should link to them via SeeAlso directive in docstring and vice versa.

    documentation 
    opened by dduan 1
  • Add overload resolution hint for + operator

    Add overload resolution hint for + operator

    Unfortunately the overload resolution rule changed between Swift 5.3 and 5.4. We need to give the compiler the hint that the most generic overloads should have the lower priority.

    opened by dduan 0
Releases(0.4.2)
  • 0.4.2(Aug 23, 2021)

    • Fixed a problem where the + operator overload resolves in ambiguity when used on a Path and a string literal. This problem is due to Swift 5.4's behaviral change.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.1(Aug 22, 2021)

  • 0.4.0(Dec 18, 2020)

    BREAKING CHANGES

    While the functionality of this library remain compatible with previous release, its public API has gone through a major re-design, making this release significantly source-breaking.

    The goals for the redesign are

    1. Be more conventional in the Swift ecosystem by eliminating the "free functions".
    2. Make the selection of APIs cross-platform, including macOS, Linux, Windows 10, and future platforms Swift runs on.
    3. Use un-decoded, aka binary representation for the path value internally for efficiency and correctness reasons.

    Experimental Windows 10 Support

    This release includes implementation of all APIs for Windows 10. As Swift on Windows 10 is still at early stage, Pathos consider its current Windows support experimental. All unit tests pass on Windows. Pathos includes CMake builds as well as SwiftPM builds (as of this release, SwiftPM support is tested with WSL).

    New

    Documentation rewritten in Markdown format replaces the previously generated documentation.

    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Sep 21, 2020)

  • 0.3.1(Sep 19, 2020)

    • children() can follow symlinks found in the content if followSymlink parameter is set to True.
    • expand Linux distro support to match that of Swift's.
    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Jul 1, 2020)

    Fixes

    • Warnings in Swift 5.3

    New

    • Added a new type Metadata, which represents information from stat (Darwin, Linux).
    • Added API to retrieve Metadata.
    • PathRepresentable.set(_:) (permissions)

    Deprecations

    The following APIs are deprecated in favor of metadata access APIs.

    • size(atPath)
    • modificationTime(atPath:)
    • accessTime(atPath:)
    • metadataChangeTime(atPath:)
    • PathRepresentable.size
    • PathRepresentable.modificationTime
    • PathRepresentable.accessTime
    • PathRepresentable.metadataChangeTime
    • permissions(forPath:)
    • PathRepresentable.permissions

    Removed adding/removing permissions in favor of directly setting it:

    • add(_:forPath:)
    • remove(_:forPath:)
    • PathRepresentable.add(_:)
    • PathRepresentable.remove(_:)

    Previously symbolic links were referred to as "symbol" or "symbolic link" in APIs. From this version on, they'll be referred to as "symlink". This resulted in the following changes:

    • createSymbolicLink(fromPath:toPath:) -> createSymlink(fromPath:toPath:)
    • PathRepresentable.createSymbolicLink(at:) -> PathRepresentable.createSymlink(at:)
    • readSymbolicLink(atPath:toPath) -> readSymlink(atPath:toPath)
    • PathRepresentable.readSymbolicLink() -> PathRepresentable.readSymlink()
    • FileType.symbolicLink -> FileType.symlink

    Carthage is no longer supported.

    Breaking changes

    Previously symbolic links were referred to as "symbol" or "symbolic link" in APIs. From this version on, they'll be referred to as "symlink". This resulted in the following breaking changes:

    • exists(atPath:followSymbol:) -> exists(atPath:followSymlink:)
    • PathRepresentable.exists(followSymbol:) -> PathRepresentable.exists(followSymlink:)
    • copyFile(fromPath:toPath:followSymbolicLink:checkSize:) -> copyFile(fromPath:toPath:followSymlink:checkSize:)
    • PathRepresentable.copy(to:followSymbolicLink:checkSize:) -> PathRepresentable.copy(to:followSymlink:checkSize:)
    c0a33d66a22521493e8ef30a40306800442ba46100ad15e6682172e369a06976  0.3.0.tar.gz
    5f28bcbc7f4f1c773ac5287a250ae92d034c32a5021b36fbdaa21249538ec7b5  0.3.0.zip
    
    Source code(tar.gz)
    Source code(zip)
  • 0.2.3(Apr 3, 2020)

    • Re-implemented children(inPath:recursive) to fix issue #122
    1909614ae4daf87749ac3e773acc23383244891ee383d86ba502d925f353ffea  0.2.3.tar.gz
    04307d24befed1d304f05d152cb3f99e8d72aaff10119267e5fcf7bcf5c36610  0.2.3.zip
    54c99f67f57b6a552e1594155ccd03eeede166fae40031d80e2a954654b620d1  Pathos.framework.zip
    
    Source code(tar.gz)
    Source code(zip)
    Pathos.framework.zip(597.94 KB)
  • 0.2.2(Mar 9, 2020)

  • 0.1.3(Apr 7, 2019)

  • 0.1.1(Mar 27, 2019)

  • 0.0.5(Mar 11, 2019)

  • 0.0.3(Jan 15, 2019)

    Update APIs for writing to files. The main change include having a sensible default permission for new files, and accepting non UInt8 byte sequence.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Jan 3, 2019)

Owner
Daniel Duan
https://duan.ca
Daniel Duan
Edit a file, create a new file, and clone from Bitbucket in under 2 minutes

Edit a file, create a new file, and clone from Bitbucket in under 2 minutes When you're done, you can delete the content in this README and update the

Nikunj Munjiyasara 0 Nov 9, 2021
Effortless path operations in Swift

PathKit Effortless path operations in Swift. Usage let path = Path("/usr/bin/swift") Joining paths let path = Path("/usr/bin") + Path("swift") Determi

Kyle Fuller 1.4k Jan 5, 2023
FileExplorer is a powerful iOS file browser that allows its users to choose and remove files and/or directories

FileExplorer (iOS 9.0+) ?? Project created and maintained by Rafał Augustyniak. You can find me on twitter (@RaAugustyniak). Introduction FileExplorer

Rafał Augustyniak 717 Dec 19, 2022
A micro-framework for observing file changes, both local and remote. Helpful in building developer tools.

KZFileWatchers Wouldn't it be great if we could adjust feeds and configurations of our native apps without having to sit back to Xcode, change code, r

Krzysztof Zabłocki 1k Dec 19, 2022
zip file I/O library for iOS, macOS and tvOS

ZipZap is a zip file I/O library for iOS, macOS and tvOS. The zip file is an ideal container for compound Objective-C documents. Zip files are widely

Glen Low 1.2k Dec 27, 2022
Zero-setup P2P file transfer between Macs and iOS devices

?? Ares Zero-setup* P2P file transfer between Macs and iOS devices Ares is a service that I built in under 24 hours, winning first place at HackED 201

Indragie Karunaratne 131 Jan 10, 2022
RavynOS File manager built in Cocoa/Appkit and ObjC

Filer A file manager and re-implementation of macOS's Finder. A key component of ravynOS, Filer is the first application you see after you start ravyn

RavynSoft 8 Oct 3, 2022
NV_MVVM-C is a template file generator. This can reduce the time taken to write the boilerplate code and create the files.

NV_MVVM-C Template, is an MVVM-C Boilerplate generator which will help you generate all the necessary files for your project architected in MVVM-C.

Nikhil Vinod 9 Sep 6, 2022
Finder-style iOS file browser written in Swift

FileBrowser iOS Finder-style file browser in Swift 4.0 with search, file previews and 3D touch. Simple and quick to use. Features ✨ Features ?? Browse

Roy Marmelstein 1.5k Dec 16, 2022
'Root' filesystem File Provider extension for iOS.

RootFSProvider This sample project was previously available on on Patreon. It is written in Objective-C, and has not been updated for newer APIs since

Steven Troughton-Smith 14 Sep 24, 2022