Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring Brightway Project Error ReadError: not a gzip file #37

Open
michaelweinold opened this issue Sep 17, 2023 · 1 comment
Open
Assignees
Labels
bug Something isn't working infrastructure

Comments

@michaelweinold
Copy link
Collaborator

michaelweinold commented Sep 17, 2023

@michaelweinold michaelweinold self-assigned this Sep 17, 2023
@michaelweinold michaelweinold added bug Something isn't working infrastructure labels Sep 17, 2023
@michaelweinold
Copy link
Collaborator Author

Using a test file (gzipped tarball) generated using

import os
import random
import string
import tarfile
import gzip

def create_tarball_and_gzip(tarball_name, num_files):
    # Generate some files to include in the tarball
    for i in range(num_files):
        # Generate a random string of at least 10MB
        file_size = 10 * 1024 * 1024
        while True:
            file_data = ''.join(random.choices(string.ascii_uppercase + string.digits, k=file_size))
            if len(file_data.encode('utf-8')) >= file_size:
                break
        
        # Write the file to disk
        with open(f'file_{i}.txt', 'w') as f:
            f.write(file_data)
    
    # Create the tarball
    with tarfile.open(tarball_name, 'w') as tar:
        for i in range(num_files):
            tar.add(f'file_{i}.txt')
    
    # Gzip the tarball
    with open(tarball_name, 'rb') as f_in:
        with gzip.open(tarball_name + '.gz', 'wb') as f_out:
            f_out.writelines(f_in)
    
    # Clean up the files
    for i in range(num_files):
        os.remove(f'file_{i}.txt')
create_tarball_and_gzip('testball', 10)

seems to work fine:

tarfile.open(
    name = 'testball.gz',
    mode = 'r:gz'
)
<tarfile.TarFile at 0x2e39d00>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working infrastructure
Projects
None yet
Development

No branches or pull requests

1 participant