mirror of
https://github.com/StikDebug/StikJIT.git
synced 2026-10-15 20:10:31 +00:00
feat: support base64 custom scripts
This commit is contained in:
parent
ee457f2f40
commit
5d732f94b8
4 changed files with 26 additions and 5 deletions
|
|
@ -3,7 +3,8 @@ import Foundation
|
|||
enum BundledScript {
|
||||
|
||||
static func source(for script: StikJIT.Script) throws -> String {
|
||||
if case .custom(let url) = script {
|
||||
switch script {
|
||||
case .custom(let url):
|
||||
guard url.isFileURL else {
|
||||
throw StikJITError.customScript("expected a file URL")
|
||||
}
|
||||
|
|
@ -18,6 +19,19 @@ enum BundledScript {
|
|||
} catch {
|
||||
throw StikJITError.customScript("could not read \(url.path): \(error.localizedDescription)")
|
||||
}
|
||||
case .customBase64(let encodedSource):
|
||||
guard let data = Data(base64Encoded: encodedSource) else {
|
||||
throw StikJITError.customScript("the provided script data is not valid base64")
|
||||
}
|
||||
guard let source = String(data: data, encoding: .utf8) else {
|
||||
throw StikJITError.customScript("the decoded script data is not valid UTF-8")
|
||||
}
|
||||
guard !source.isEmpty else {
|
||||
throw StikJITError.customScript("the decoded script is empty")
|
||||
}
|
||||
return source
|
||||
case .universal, .legacy:
|
||||
break
|
||||
}
|
||||
|
||||
let bundle = Bundle(for: BundleToken.self)
|
||||
|
|
|
|||
|
|
@ -10,11 +10,14 @@ public enum StikJIT {
|
|||
|
||||
case custom(URL)
|
||||
|
||||
case customBase64(String)
|
||||
|
||||
var name: String {
|
||||
switch self {
|
||||
case .universal: return "universal"
|
||||
case .legacy: return "legacy"
|
||||
case .custom(let url): return url.lastPathComponent
|
||||
case .customBase64: return "custom"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue