Skip to content

Instantly share code, notes, and snippets.

@iacore
Created April 1, 2023 14:17
Show Gist options
  • Save iacore/10a86b73521decc0789d22b0ed680806 to your computer and use it in GitHub Desktop.
Save iacore/10a86b73521decc0789d22b0ed680806 to your computer and use it in GitHub Desktop.
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