itty-bitty
itty-bitty copied to clipboard
Generating a site with Swift?
Hey there - anyone had any luck compressing a site with Swift? I've tried this, but the result is different than if I do it on the command line
let raw : Data! = String("hello world").data(using: .utf8)
let compressed2 = try! (raw as NSData).compressed(using: .lzma)
print("https://itty.bitty.site/#/" + compressed2.base64EncodedString(options: []))
It outputs
https://itty.bitty.site/#//Td6WFoAAAD/EtlBAgAhARYAAAB0L+WjAQAKaGVsbG8gd29ybGQAAAABGws5p2IeBnKeegEAAAAAAFla
But it should be
https://itty.bitty.site/#/XQAAQAD//////////wA0GUnujekXiTozYAX3z2T/+3ggAA==
The weird thing is that it works in the other direction
let encoded = "XQAAAAT//////////wA0GUnujekXiTozYAX3z2T/+3ggAA=="
let uncData = try! NSData(base64Encoded: encoded, options: .ignoreUnknownCharacters)!
.decompressed(using: .lzma)
String(data: uncData as Data, encoding: .utf8) // prints hello world