File: edit-compressed

package info (click to toggle)
debsecan 0.4.20.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 816 kB
  • sloc: python: 1,184; sh: 255; makefile: 19
file content (18 lines) | stat: -rw-r--r-- 419 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/python3

import os
import sys
import tempfile
import zlib

input_name = sys.argv[1]
data = zlib.decompress(open(input_name, "rb").read())
(tmp, tmp_name) = tempfile.mkstemp()
try:
    with open(tmp_name, "wb") as tmp:
        tmp.write(data)
    os.system("editor " + tmp_name)
    data = zlib.compress(open(tmp_name, "rb").read(), 9)
    open(input_name, "wb+").write(data)
finally:
    os.unlink(tmp_name)