GKM__
GKM__

Reputation: 109

Open .json.xz files

I have a list of directories, in which are contained sub-directories. In each sub-directories there are some 'json.xz' compressed file. If I try to open one of them with my code I get the error:

raise EOFError("Compressed file ended before the "
EOFError: Compressed file ended before the end-of-stream marker was reached

This is my code:

subject = 'AntonioGio'
path = '/home/rootdebian/Scrivania/Socialisys/projects/'+subject+'/competitor/'


for competitors in os.listdir(path):
    for f in os.listdir(path+competitors):
        if f.endswith('.xz'):
            with lzma.open(path+competitors+'/'+f) as f:
                json_bytes = f.read()
                stri = json_bytes.decode('utf-8')
                data = json.loads(stri)

                print(data)

what is the best way to fix it? Thank you in advice.

Upvotes: 2

Views: 5046

Answers (1)

Teddy Haley
Teddy Haley

Reputation: 93

This is probably because the compressed data file you have is incomplete/corrupted. The code you have provided works fine for decompressing json.xz files.

Upvotes: 2

Related Questions