存储是用于资源存储 API 的通用接口,例如 Google Cloud Storage、Amazon S3 或您的本地文件系统。
将软件包实例添加到清单文件的 dependencies 数组中,并使用最新版本
.package(url: "https://github.com/skelpo/Storage.git", from: "0.1.0")
然后运行 swift package update,如果您有 Xcode 项目,请重新生成。
Storage 软件包围绕 Storage 协议构建,该协议定义了一种可以创建、读取、更新和删除文件的类型。
它需要 4 个方法
func store(file: File, at path: String?) -> EventLoopFuture<String>func fetch(file: String) -> EventLoopFuture<File>func write(file: String, with data: Data) -> EventLoopFuture<File>func delete(file: String) -> EventLoopFuture<Void>一种 Swift 类型,表示具有名称 String 和内容为 ByteBuffer 的文件。
如果在 Storage 方法中发生任何错误,则会在 future 中返回 StorageError。如果您创建自己的 Storage 实现,请使用此错误。
用于与本地文件系统中文件交互的 Storage 实现。store 和 fetch 方法流式传输文件数据,而 delete 和 write 方法在实例的事件循环中运行。
您可以在此处查看 API 文档。
此软件包已根据 MIT 许可协议注册。