Swiftpack.co -  Package - BinaryBirds/liquid-local-driver
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A local driver implementation for the LiquidKit file storage solution.
.package(url: "https://github.com/BinaryBirds/liquid-local-driver.git", from: "1.2.0")


A local driver implementation for the LiquidKit file storage solution.

The local driver uses a local directory on the server and the FileManager object from the Foundation framework to store files. If you are planning to setup a distributed system with multiple application servers, please consider using the AWS S3 driver instead.

LiquidKit and the local driver is also compatible with Vapor 4 through the Liquid repository, that contains Vapor specific extensions.

Key resolution for local objects

Keys are being resolved using a public base URL component, the name of the working directory and the key itself.

  • url = [public base URL] + [working directory name] + [key]


Usage with SwiftNIO

Add the required dependencies using SPM:

// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "myProject",
    platforms: [
    dependencies: [
        .package(url: "https://github.com/binarybirds/liquid", from: "1.2.0"),
        .package(url: "https://github.com/binarybirds/liquid-local-driver", from: "1.2.0"),
    targets: [
        .target(name: "App", dependencies: [
            .product(name: "Liquid", package: "liquid"),
            .product(name: "LiquidLocalDriver", package: "liquid-local-driver"),

A basic usage example with SwiftNIO:

/// setup thread pool
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let pool = NIOThreadPool(numberOfThreads: 1)

/// create fs  
let fileio = NonBlockingFileIO(threadPool: pool)
let storages = FileStorages(fileio: fileio)
storages.use(.local(publicUrl: "http://localhost/",
                    publicPath: "/var/www/localhost/public",
                    workDirectory: "assets"), as: .local)
let fs = storages.fileStorage(.local, logger: .init(label: "[test-logger]"), on: elg.next())!

/// test file upload
let key = "test.txt"
let data = Data("file storage test".utf8)
let res = try fs.upload(key: key, data: data).wait()

/// http://localhost/assets/test.txt
let url = req.fs.resolve(key: key)

/// delete key
try req.fs.delete(key: key).wait()


Stars: 5
Last commit: 5 weeks ago


Release Notes

New API methods
5 weeks ago
  • New API methods, based on LiquidKit
  • Better documentation & README
  • Dependency updates (liquid-kit v1.2.0)

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