Banner

Pathos 为 Swift 提供跨平台虚拟文件系统 API。

Pathos 完全基于每个操作系统的原生 API 实现,不依赖任何其他库。

目前 Windows 支持被认为是实验性的

持续集成
Amazon Linux 2
macOS 11.15
Ubuntu Bionic
Ubuntu Focal
Windows 2019 (实验性)

想要体验 Pathos 吗?让我们用 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

如您所见,Pathos 提供了一整套用于检查和操作文件系统的 API。 使用 Pathos 构建的程序可以在所有受支持的操作系统上编译和运行,而无需在源代码中使用 #if OS()

好奇的话,可以查看更多示例

安装

使用 SwiftPM

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

文档

  1. 用户指南 - Pathos 的入门教程。
  2. API 参考 - 完整的 Pathos 公共 API 参考。
  3. 设计 - 解释 API 如此设计的原因。
  4. 更新日志 - 所有 Pathos 版本的更改日志。

您还可以查看示例应用程序

许可证

Pathos 在 MIT 许可证下发布。 请参阅 LICENSE.md