#!/usr/bin/env python3
import zstandard as zstd
import sys

def repair_zst(filename):
    try:
        with open(filename, 'rb') as f:
            dctx = zstd.ZstdDecompressor()
            output_file = filename.replace('.zst', '')
            
            with open(output_file, 'wb') as out:
                try:
                    for chunk in dctx.stream_reader(f):
                        out.write(chunk)
                except Exception as e:
                    print(f"Stopped at error: {e}")
                    print(f"Partial data written to: {output_file}")
                    return True
        return True
    except Exception as e:
        print(f"Failed: {e}")
        return False

if __name__ == "__main__":
    repair_zst(sys.argv[1])
