veg / hivtrace

MIT License
22 stars 15 forks source link

Only unpack resources if necessary #91

Closed FynnFreyer closed 11 months ago

FynnFreyer commented 11 months ago

It would be nice if hivtrace would only unpack resource files if they're not found. This would have two advantages:

  1. Packaging hivtrace in a container with a read only FS (like apptainer) becomes feasible.
  2. Minor performance improvement after the first run.

The following code would need to be changed:

https://github.com/veg/hivtrace/blob/e1164ddbb2bd6d0d7d7a8163e6c47f2cf7f44995/hivtrace/hivtrace.py#L67-L70

An implementation could look like this:

def gunzip_file(zip_file, out_file):
    if not os.path.isfile(out_file):
        with gzip.open(zip_file, 'rb') as f_in:
            with open(out_file, 'wb') as f_out:
                f_out.writelines(f_in)

Or, using a compound with statement:

def gunzip_file(zip_file, out_file):
    if not os.path.isfile(out_file):
        with gzip.open(zip_file, 'rb') as f_in, open(out_file, 'wb') as f_out:
            f_out.writelines(f_in)