Swiftpack.co - BinaryBirds/liquid-local-driver as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by BinaryBirds.
BinaryBirds/liquid-local-driver 1.3.2
A local driver implementation for the LiquidKit file storage solution.
⭐️ 7
🕓 2 years ago
macOS
.package(url: "https://github.com/BinaryBirds/liquid-local-driver.git", from: "1.3.2")

LiquidLocalDriver

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]

e.g.

Usage with SwiftNIO

Add the required dependencies using SPM:

// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "myProject",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        .package(url: "https://github.com/binarybirds/liquid", from: "1.3.0"),
        .package(url: "https://github.com/binarybirds/liquid-local-driver", from: "1.3.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)
pool.start()

/// 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 await fs.upload(key: key, data: data)

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

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

GitHub

link
Stars: 7
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

macOS 10.15 support
2 years ago

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