Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 5d9627c

Browse files
authored
Merge pull request #9 from heidipuk/update-to-vapor3
Update to vapor3
2 parents 0916cd7 + ffef8f8 commit 5d9627c

13 files changed

Lines changed: 111 additions & 41 deletions

.circleci/config.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ version: 2
22
jobs:
33
MacOS:
44
macos:
5-
xcode: "9.0"
5+
xcode: "10.0"
66
steps:
77
- checkout
88
- restore_cache:
99
keys:
1010
- v1-spm-deps-{{ checksum "Package.swift" }}
1111
- run:
12-
name: Install CMySQL and CTLS
12+
name: Install dependencies
1313
command: |
1414
brew tap vapor/homebrew-tap
1515
brew install cmysql
1616
brew install ctls
17+
brew install libressl
1718
- run:
1819
name: Build and Run Tests
1920
no_output_timeout: 1800
@@ -30,22 +31,22 @@ jobs:
3031
- .build
3132
Linux:
3233
docker:
33-
- image: brettrtoomey/vapor-ci:0.0.1
34+
- image: nodesvapor/vapor-ci:swift-4.2
3435
steps:
3536
- checkout
3637
- restore_cache:
3738
keys:
3839
- v2-spm-deps-{{ checksum "Package.swift" }}
3940
- run:
40-
name: Copy Package file
41+
name: Copy Package File
4142
command: cp Package.swift res
4243
- run:
4344
name: Build and Run Tests
4445
no_output_timeout: 1800
4546
command: |
4647
swift test -Xswiftc -DNOJSON
4748
- run:
48-
name: Restoring Package file
49+
name: Restoring Package File
4950
command: mv res Package.swift
5051
- save_cache:
5152
key: v2-spm-deps-{{ checksum "Package.swift" }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ xcuserdata/
2323
## Other
2424
*.moved-aside
2525
*.xcuserstate
26+
test.Dockerfile
27+
dockerTest.sh
2628

2729
## Obj-C/Swift specific
2830
*.hmap
@@ -39,6 +41,7 @@ playground.xcworkspace
3941
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
4042
# Packages/
4143
.build/
44+
Package.resolved
4245

4346
# CocoaPods
4447
#

Package.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
// swift-tools-version:4.2
2+
13
import PackageDescription
24

35
let package = Package(
46
name: "DataURI",
7+
products: [
8+
.library(name: "DataURI", targets: ["DataURI"])
9+
],
510
dependencies: [
6-
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
11+
.package(url: "https://github.com/vapor/core.git", from: "3.0.0"),
12+
],
13+
targets: [
14+
.target(
15+
name: "DataURI",
16+
dependencies: ["Core"]
17+
),
18+
.testTarget(
19+
name: "DataURITests",
20+
dependencies: ["DataURI"]
21+
)
722
]
823
)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DataURI
2-
[![Swift Version](https://img.shields.io/badge/Swift-3-brightgreen.svg)](http://swift.org)
3-
[![Vapor Version](https://img.shields.io/badge/Vapor-2-F6CBCA.svg)](http://vapor.codes)
2+
[![Swift Version](https://img.shields.io/badge/Swift-4.2-brightgreen.svg)](http://swift.org)
3+
[![Vapor Version](https://img.shields.io/badge/Vapor-3-30B6FC.svg)](http://vapor.codes)
44
[![Circle CI](https://circleci.com/gh/nodes-vapor/data-uri/tree/master.svg?style=shield)](https://circleci.com/gh/nodes-vapor/data-uri)
55
[![codebeat badge](https://codebeat.co/badges/7f0cab4f-f11b-43d5-8484-bc9300c23d81)](https://codebeat.co/projects/github-com-nodes-vapor-data-uri-master)
66
[![codecov](https://codecov.io/gh/nodes-vapor/data-uri/branch/master/graph/badge.svg)](https://codecov.io/gh/nodes-vapor/data-uri)
@@ -14,7 +14,7 @@ A pure Swift parser for Data URIs.
1414

1515
Update your `Package.swift` file.
1616
```swift
17-
.Package(url: "https://github.com/nodes-vapor/data-uri.git", majorVersion: 1)
17+
.package(url: "https://github.com/nodes-vapor/data-uri.git", from: "2.0.0")
1818
```
1919

2020

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public typealias Byte = UInt8
2+
public typealias Bytes = [Byte]
3+
4+
extension Byte {
5+
internal var asciiCode: Byte {
6+
if self >= 48 && self <= 57 {
7+
return self - 48
8+
} else if self >= 65 && self <= 70 {
9+
return self - 55
10+
} else {
11+
return 0
12+
}
13+
}
14+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Core
21
import Foundation
32

43
extension String {
@@ -11,4 +10,9 @@ extension String {
1110
let (data, type, _) = try DataURIParser.parse(uri: self)
1211
return (data, type.makeString())
1312
}
13+
14+
/// Converts the string to a UTF8 array of bytes.
15+
public var bytes: [UInt8] {
16+
return [UInt8](self.utf8)
17+
}
1418
}
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ public struct DataURIParser {
66
case invalidScheme
77
case invalidURI
88
}
9-
109
var scanner: Scanner<Byte>
1110

1211
init(scanner: Scanner<Byte>) {
@@ -41,10 +40,13 @@ extension DataURIParser {
4140
type = "text/plain;charset=US-ASCII".bytes
4241
}
4342

44-
if let typeMetadata = typeMetadata, typeMetadata == "base64".bytes {
45-
data = data.base64Decoded
43+
if typeMetadata == "base64".bytes,
44+
let decodedData = Data(base64Encoded: data.convertToData()),
45+
let dataString = String(data: decodedData, encoding: .utf8)
46+
{
47+
data = dataString.bytes
4648
}
47-
49+
4850
return (data, type, typeMetadata)
4951
}
5052
}
@@ -150,15 +152,3 @@ extension DataURIParser {
150152
return (leftMostDigit.asciiCode * 16) + rightMostDigit.asciiCode
151153
}
152154
}
153-
154-
extension Byte {
155-
internal var asciiCode: Byte {
156-
if self >= 48 && self <= 57 {
157-
return self - 48
158-
} else if self >= 65 && self <= 70 {
159-
return self - 55
160-
} else {
161-
return 0
162-
}
163-
}
164-
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extension Sequence where Iterator.Element == Byte {
2+
/// Converts a slice of bytes to
3+
/// string. Courtesy of Vapor 2 - Core and @vzsg
4+
public func makeString() -> String {
5+
let array = Array(self) + [0]
6+
7+
return array.withUnsafeBytes { rawBuffer in
8+
guard let pointer = rawBuffer.baseAddress?.assumingMemoryBound(to: CChar.self) else { return nil }
9+
return String(validatingUTF8: pointer)
10+
} ?? ""
11+
}
12+
}

Tests/DataURITests/DataURITests.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ class DataURITests: XCTestCase {
1414
("testSpeed", testSpeed)
1515
]
1616

17-
func testBase64() {
18-
//FIXME(Brett): remove when vapor/core is updated to 1.1
19-
let base64Bytes: Bytes = "SGVsbG8sIHdvcmxkIQ==".makeBytes()
20-
let output: Bytes = base64Bytes.base64URLDecoded
21-
XCTAssertEqual(output.makeString(), "Hello, world!")
22-
}
23-
2417
func testTextNoType() {
2518
let (data, type, meta) = try! DataURIParser.parse(
2619
uri: "data:,Hello%2C%20World!"

0 commit comments

Comments
 (0)