From c50a8fd796a26b8c69076bce2e1758b0a0c70b0f Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 22 Nov 2021 23:10:19 +0000 Subject: [PATCH] Fix 'Dictionary mismatch' error when very small dicts are used because the temporary file isn't written to disk before zstdcat gets executed --- zstdwarccat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zstdwarccat b/zstdwarccat index 6f92414..17cb43c 100755 --- a/zstdwarccat +++ b/zstdwarccat @@ -47,10 +47,14 @@ if len(sys.argv) == 2: d = get_dict(fp) else: d = get_dict(sys.stdin.buffer.raw) -with tempfile.NamedTemporaryFile() as dfp: +# The file must be written to the file system before zstdcat is executed. The most reliable way for that is to close the file. This requires manually deleting it at the end. +with tempfile.NamedTemporaryFile(delete = False) as dfp: dfp.write(d) +try: args = ['zstdcat', '-D', dfp.name] if len(sys.argv) == 2: args.append(sys.argv[1]) pzstd = subprocess.Popen(args) pzstd.communicate() +finally: + os.remove(dfp.name)