Swiftpack.co - Frizlab/swift-xdg as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Frizlab.
Frizlab/swift-xdg 1.0.0-beta.1.0.1
Implementation of the XDG Base Directory Specification in Swift
ā­ļø 0
šŸ•“ 3 days ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/Frizlab/swift-xdg.git", from: "1.0.0-beta.1.0.1")

swift-xdg

Implementation of the XDG Base Directory Specification in Swift.

This package has been largely inspired by a Rust implementation.

Usage

let dirs = try BaseDirectories(prefixAll: "my-amazing-app")
/* Get existing configuration path. */
let confPath = try dirs.findConfigFile("conf.toml")
/* If all paths are needed, just add an ā€œsā€. */
let confPaths = try dirs.findConfigFiles("conf.toml")
/* Get path for writing new config.
 * The method makes sure the parent directory exists for the file 
 *  and return the path where the file should be. */
let newConfPath = try dirs.ensureParentsForConfigFilePath("conf.toml")

This particular implementation of the Base Directory Specification makes sure the paths returned never escape the homes in which they should be.

For instance if XDG_CONFIG_HOME=/home/frizlab/.config, we make sure none of the functions that return a config path in this package would return a path outside of this folder, whichever prefixes and file names are required.

A simple example: let confPath = try dirs.findConfigFile("../conf.toml") will throw.

GitHub

link
Stars: 0
Last commit: 3 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

1.0 beta 1
2 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics