Swiftpack.co -  nodes-vapor/data-uri as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A pure Swift parser for Data URIs.
.package(url: "https://github.com/nodes-vapor/data-uri.git", from: "2.0.1")


Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

A pure Swift parser for Data URIs.

๐Ÿ“ฆ Installation

Update your Package.swift file.

.package(url: "https://github.com/nodes-vapor/data-uri.git", from: "2.0.0")

Getting started ๐Ÿš€

There are two options for decoding a Data URI. The first is using the String extension and the second is by using the DataURIParser directly.

The String method

This method is by far the easiest to use. All you need to do is call .dataURIDecoded() throws -> (data: Bytes, type: String) on any Data URI encoded String.

import Core //just for `Bytes.string`
import DataURI

let uri = "data:,Hello%2C%20World!"
let (data, type) = try uri.dataURIDecoded()
print(data.string) // "Hello, World!"
print(type) // "text/plain;charset=US-ASCII"

The DataURIParser method

Using the parser is a bit more involved as it returns all of its results as Bytes.

import Core //just for `Bytes.string`
import DataURI

let uri = "data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E"
let (data, type, metadata) = try DataURIParser.parse(uri: uri)
print(data.string) // "<h1>Hello, World!</h1>"
print(type.string) // "text/html"
print(metadata == nil) // "true"

๐Ÿ† Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Tom.

๐Ÿ“„ License

This package is open-sourced software licensed under the MIT license


Stars: 9
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jackโ€™d and SCRUFF. We are two of the worldโ€™s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Version 2.0.1
4 weeks ago

Fix data corruption with binary data uri

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