{"id":21846629,"url":"https://github.com/binarybirds/liquid-kit","last_synced_at":"2025-07-20T20:30:51.595Z","repository":{"id":49187211,"uuid":"259677801","full_name":"BinaryBirds/liquid-kit","owner":"BinaryBirds","description":"An abstract FileStorage solution, based on the SwiftNIO framework.","archived":false,"fork":false,"pushed_at":"2023-02-14T15:19:22.000Z","size":48,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2023-03-05T06:55:03.626Z","etag":null,"topics":["file-storage","swift-logger","swift-nio"],"latest_commit_sha":null,"homepage":"https://feathercms.com/","language":"Swift","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BinaryBirds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-28T15:32:09.000Z","updated_at":"2022-08-12T20:43:38.000Z","dependencies_parsed_at":"2023-02-10T06:15:27.369Z","dependency_job_id":null,"html_url":"https://github.com/BinaryBirds/liquid-kit","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryBirds%2Fliquid-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryBirds%2Fliquid-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryBirds%2Fliquid-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinaryBirds%2Fliquid-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BinaryBirds","download_url":"https://codeload.github.com/BinaryBirds/liquid-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226832385,"owners_count":17689141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-storage","swift-logger","swift-nio"],"created_at":"2024-11-27T23:14:48.922Z","updated_at":"2024-11-27T23:14:49.494Z","avatar_url":"https://github.com/BinaryBirds.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LiquidKit\n\nAn abstract FileStorage solution, based on the SwiftNIO framework.\n\n\n## Key-based file storage \n\n- The main concept of LiquidKit is somewhat similar how AWS S3 buckets work.\n- You can use keys (relative path components) to store files using various drivers.\n- Keys should be designed to work with all the supported drivers.\n- Drivers should provide a resolution mechanism to return the absolute URL for a given key.\n\ne.g. \n\nthe key \"test.txt\" could be resolved to \"http://localhost:8080/assets/test.txt\" when using the local fs driver.\n\n\n## Drivers and Vapor 4 support\n\nCurrently available drivers:\n\n- [local](https://github.com/BinaryBirds/liquid-local-driver)\n- [AWS S3](https://github.com/BinaryBirds/liquid-aws-s3-driver)\n\nLiquidKit is also compatible with Vapor 4 through the [Liquid](https://github.com/BinaryBirds/liquid) repository, that contains Vapor specific extensions.\n\n\n## Usage with SwiftNIO\n\nYou can use the Liquid FileStorage driver directly with SwiftNIO, here's a possible usage example:   \n\n```\n/// setup thread pool\nlet elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)\nlet pool = NIOThreadPool(numberOfThreads: 1)\npool.start()\n\n/// create fs  \nlet fileio = NonBlockingFileIO(threadPool: pool)\nlet storages = FileStorages(fileio: fileio)\nstorages.use(.custom(exampleConfigVariable: \"assets\"), as: .custom)\nlet fs = storages.fileStorage(.custom, logger: .init(label: \"[test-logger]\"), on: elg.next())!\n\n/// test file upload\nlet key = \"test.txt\"\nlet data = Data(\"file storage test\".utf8)\nlet res = try fs.upload(key: key, data: data).wait()\n\n```\n\n\n## How to implement a custom driver?\n\nDrivers should implement the following protocols:\n\n\n### FileStorageID\n\nUsed to uniquely identify the file storage driver.\n\n```swift\npublic extension FileStorageID {\n    static var customDriver: FileStorageID { .init(string: \"custom-driver-identifier\") }\n}\n```\n\n### FileStorageConfiguration\n\nA custom set of configuration variables required to initialize or setup the driver. \n\n```swift\nstruct LiquidCustomStorageConfiguration: FileStorageConfiguration {\n    let exampleConfigVariable: String\n\n    func makeDriver(for storages: FileStorages) -\u003e FileStorageDriver {\n        return LiquidCustomStorageDriver(fileio: storages.fileio, configuration: self)\n    }\n}\n```\n\n### FileStorageDriver\n\nThe file storage driver used to create the underlying storage object (that implements the API methods) using the configuration and context.\n\n```swift\nstruct LiquidCustomStorageDriver: FileStorageDriver {\n\n    let fileio: NonBlockingFileIO\n    let configuration: LiquidCustomStorageConfiguration\n\n    func makeStorage(with context: FileStorageContext) -\u003e FileStorage {\n        LiquidCustomStorage(fileio: fileio, configuration: configuration, context: context)\n    }\n    \n    func shutdown() {\n\n    }\n}\n```\n\n### FileStorage\n\nActual storage implementation that handles the necessary API methods.\n\n```swift\n\nstruct LiquidCustomStorage: FileStorage {\n\n    let fileio: NonBlockingFileIO\n    let configuration: LiquidCustomStorageConfiguration\n    let context: FileStorageContext\n    \n    \n    init(fileio: NonBlockingFileIO, configuration: LiquidCustomStorageConfiguration, context: FileStorageContext) {\n        self.fileio = fileio\n        self.configuration = configuration\n        self.context = context\n    }\n\n    // MARK: - api\n\n    func resolve(key: String) -\u003e String { /* ... */ }\n    func upload(key: String, data: Data) async throws -\u003e String { /* ... */ }\n    func createDirectory(key: String) async throws { /* ... */ }\n    func list(key: String?) async throws -\u003e [String] { /* ... */ }\n    func copy(key source: String, to destination: String) async throws -\u003e String { /* ... */ }\n    func move(key source: String, to destination: String) async throws -\u003e String { /* ... */ }\n    func delete(key: String) async throws { /* ... */ }\n    func exists(key: String) async -\u003e Bool { /* ... */ }\n}\n```\n\n### FileStorageConfigurationFactory\n\nAn extension on the FileStorageConfigurationFactory object that helps you to create the custom driver with the necessary config values.\n\n```swift\npublic extension FileStorageConfigurationFactory {\n\n    static func custom(exampleConfigVariable: String) -\u003e FileStorageConfigurationFactory {\n        .init { LiquidCustomStorageConfiguration(exampleConfigVariable) }\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinarybirds%2Fliquid-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinarybirds%2Fliquid-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinarybirds%2Fliquid-kit/lists"}