Skip to content

Commit

Permalink
use swift-extras-base64 when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
lockieluke committed Mar 9, 2024
1 parent 14ad456 commit 22004e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ toml = "0.8.8"
serde = { version = "1.0.195", features = ["derive"] }

[[bin]]
name = "swift-precompiler"
name = "swift-precompiler"

[profile.release]
lto = true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ swift-precompiler precompile
```

<sub>You should add `Precompiled.swift` to your `.gitignore`</sub>

Swift Precompiler encodes your strings with Base64, you can add [swift-extras-base64](https://github.com/swift-extras/swift-extras-base64) to your project using SPM to enable faster Base64 decode.
7 changes: 7 additions & 0 deletions assets/PrecompiledTemplate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(ExtrasBase64)
import ExtrasBase64
#endif

extension Data {
/// Same as ``Data(base64Encoded:)``, but adds padding automatically
Expand Down Expand Up @@ -35,7 +38,11 @@ func precompileIncludeStr(_ path: String) -> String {
fatalError("Error: include file not found: \(path)")
}

#if canImport(ExtrasBase64)
return String(bytes: try! Base64.decode(string: content), encoding: .utf8)
#else
return String.fromBase64(content) ?? ""
#endif
}

func precompileIncludeData(_ path: String) -> Data {
Expand Down

0 comments on commit 22004e9

Please sign in to comment.