Created
April 1, 2023 14:17
-
-
Save iacore/10a86b73521decc0789d22b0ed680806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/[cmdline, base64] | |
proc writePng(f: File; pngdata: string) = | |
let bytes = pngdata.encode | |
const CHUNK_SIZE = 4096 | |
var remaining = bytes.len | |
var i = 0 | |
while remaining > 0: | |
let (numread, m) = | |
if remaining > CHUNK_SIZE: | |
(CHUNK_SIZE, "m=1") | |
else: | |
(remaining, "") | |
let encoded = bytes[i..<i+numread] | |
f.write "\e_G" | |
if i == 0: | |
f.write "a=T,f=100," | |
f.write m | |
f.write ";" | |
f.write encoded | |
f.write "\e\\" | |
remaining -= numread | |
i += numread | |
proc main = | |
let filename = paramStr(1) | |
stdout.writePng(readFile(filename)) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment