Decompress bz2 files

后端 未结 3 1223
余生分开走
余生分开走 2020-12-29 23:22

I would like to decompress the files in different directories which are in different routes. And codes as below and the error is invalid data stream. Please help me out. Tha

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 00:15

    bz2.decompress takes compressed data and inflates it. You pass a filename, not the data in the file!

    Do this instead:

    zipfile = bz2.BZ2File(filepath) # open the file
    data = zipfile.read() # get the decompressed data
    newfilepath = filepath[:-4] # assuming the filepath ends with .bz2
    open(newfilepath, 'wb').write(data) # write a uncompressed file
    

提交回复
热议问题