Swiftpack.co - Package - nodes-vapor/data-uri

DataURI

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", majorVersion: 1)

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

Github

link
Stars: 4
Help us keep the lights on

Dependencies

Used By

Total:

Releases

1.0.0 - May 18, 2017

  • Vapor 2 released 🎉

1.0.0-beta1 - Apr 26, 2017

0.1.1 - Dec 30, 2016

Reordered the resulting tuple for all public API calls.

0.1.0 - Dec 22, 2016

First pre-release.