itty-bitty icon indicating copy to clipboard operation
itty-bitty copied to clipboard

Generating a site with Swift?

Open mortenjust opened this issue 5 years ago • 1 comments

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==

mortenjust avatar Apr 29 '20 10:04 mortenjust

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

mortenjust avatar Apr 29 '20 11:04 mortenjust