destream

A simple module to decompress streams compressed multiple times


Keywords
stream, file, decompress, zip, zstd
License
GPL-2.0
Install
pip install destream==5.0.1

Documentation

Build Status codecov

destream

destream: decompress a stream

Compatibility

  • Python: 2.7, 3.4, 3.5, 3.6, 3.7
  • OS:
    • Linux
    • OSX is not tested
    • Windows is not tested and requires file and libmagic for Windows

Installation

pip install destream OR easy_install --user destream

Usage

  1. Decompress multiple files of anytype to directory:

    destream -o /tmp/output_dir file1.zip file2.rar file3.7z file4.tar.bz2
  2. Decompress any stream to the current folder:

    wget -O - "https://github.com/cecton/destream/archive/3.1.tar.gz" | destream -o ./
  3. Decompress any compressed file to stdout:

    destream documentation.gz | less

Lib Usage

  1. Open an archive that holds multiple files (aka: ArchivePack)
    archive = destream.open("some_file.tar.gz")
    
    assert isinstance(archive, destream.ArchivePack) \
        and isinstance(archive.tarfile, tarfile.TarFile)
    
    # ==> we can extract members using extract() and extractall()
    archive.extractall("/tmp")
  2. Open a compressed file (or stream) and get an uncompressed stream
    archive = destream.open("weird_file.bz2.gz")
    
    assert isinstance(archive, destream.Archive)
    
    # ==> we can read the content but not seek
    print(archive.read())
  3. Open an archive that holds only one file,
    archive = destream.open("some_file.tar.xz")
    
    # ==> we can read the archive like it is a stream
    if archive.single():
        print(archive.read())
    else:
        archive.extractall('/tmp/some/path/')

Troubleshooting

  • ImportError: failed to find libmagic. Check your installation

    • Mac OS X: follow these installation guide. Or simply:

      brew install libmagic
      
    • Arch Linux:

      pacman -S file
      
    • Ubuntu/Debian:

      apt-get install libmagic1
      
  • LZMA does not work

    Check your version of file and libmagic. It's working on version 5.22 and greater but not on version 5.14 and lower.

  • Zstd does not work

    Check your version of file and libmagic. It's working on version 5.32 and greater but not on version 5.25 and lower.