Skip to content

Commit

Permalink
Fixed CI & added Python 3.7
Browse files Browse the repository at this point in the history
* Fixed Travis CI build

* Updated zstd test binary blob

* Added: Python 3.7

* Fixed: change type of "information" for RAR

* Added: test the guesser alone to get better error message

* Increase major and update dependency
  • Loading branch information
cecton authored Sep 13, 2019
1 parent a9e12b4 commit 18aba2b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"

os:
- linux
# - osx # NOTE: Python is not available yet (not tested)
# - windows # NOTE: Python is not available yet

cache: pip

before_install:
- sudo apt-get install p7zip rar
- sudo sh -c 'echo "deb http://archive.ubuntu.com/ubuntu/ artful main restricted universe" > /etc/apt/sources.list'
# NOTE: attempt to get a more updated version of file and libmagic >= 5.30
- sudo sh -c 'echo "deb http://archive.ubuntu.com/ubuntu/ bionic main restricted universe" > /etc/apt/sources.list'
- sudo apt-get update
- sudo apt-get install zstd
- sudo apt-get install file libmagic1
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ 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
------------

Expand Down Expand Up @@ -52,15 +61,15 @@ Lib Usage
assert isinstance(archive, destream.Archive)
# ==> we can read the content but not seek
print archive.read()
print(archive.read())
```
3. Open an archive that holds only one file,
```python
archive = destream.open("some_file.tar.xz")
# ==> we can read the archive like it is a stream
if archive.single():
print archive.read()
print(archive.read())
else:
archive.extractall('/tmp/some/path/')
```
Expand Down
32 changes: 16 additions & 16 deletions destream/decompressors/rar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
__all__ = ['Unrar']


def parse_hunk(hunk):
info = {}
for m in re.finditer(
r'^[ \t\f]*(.+?)[ \t\f]*:[ \t\f]*(.*?)[ \t\f]*$',
hunk, flags=re.M):
key = re.sub(r'\W', '_', m.group(1).lower())
info[key] = m.group(2)
if info.get('service', '') == 'EOF':
raise StopIteration()
return info
def iter_on_hunks(hunks):
for hunk in hunks:
info = {}
for m in re.finditer(
r'^[ \t\f]*(.+?)[ \t\f]*:[ \t\f]*(.*?)[ \t\f]*$',
hunk, flags=re.M):
key = re.sub(r'\W', '_', m.group(1).lower())
info[key] = m.group(2)
if info.get('service', '') == 'EOF':
break
yield info


class Header(object):
def __init__(self, hunk):
self.__dict__.update(parse_hunk(hunk))
def __init__(self, info):
self.__dict__.update(info)
assert 'RAR' in self.details, \
"Maybe not a RAR file:%s\n" % self.details


class Member(object):
def __init__(self, hunk):
info = parse_hunk(hunk)
def __init__(self, info):
info['filename'] = info.pop('name')
info['size'] = int(info.get('size', 0))
info['packed_size'] = int(info.get('packed_size', 0))
Expand Down Expand Up @@ -76,8 +76,8 @@ def __init__(self, name, fileobj):
self.fileobj = ArchiveTemp(fileobj)
output = check_output(self._command +
['vta', self.fileobj.name]).decode()
hunks = iter(output.split("\n\n"))
self.information = next(hunks).strip()
hunks = iter_on_hunks(output.split("\n\n"))
self.information = next(hunks)
self.header = Header(next(hunks))
self._members = [m for m in (Member(h) for h in hunks)]
self._stream = (len(self._members) == 1)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name = "destream",
version = "4.2.0",
version = "5.0.0",
author = "Cecile Tonglet",
author_email = "[email protected]",
description = ("A simple module to decompress streams compressed multiple "
Expand All @@ -12,7 +12,7 @@
url = "https://github.com/cecton/destream",
packages = find_packages(),
scripts = ['scripts/destream'],
install_requires = ['python-magic==0.4.12'],
install_requires = ['python-magic>=0.4.12'],
classifiers = [
"Development Status :: 5 - Production/Stable",
"Topic :: System :: Archiving :: Compression",
Expand Down
7 changes: 6 additions & 1 deletion tests/test_30_decompressors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from io import BytesIO
import tarfile
import zipfile
import magic
try:
import unittest2 as unittest
except ImportError:
Expand All @@ -25,6 +26,10 @@ def _check_decompressor(self, decompressor, compressed_fileobj,
self.skipTest("decompressor not available")
if expected_name is None:
expected_name = decompressed_fileobj.name
archive = destream.ArchiveFile(compressed_fileobj, None, closefd=False)
mime = magic.from_buffer(archive.peek(1024), mime=True)
decompressor._guess(mime, str(archive.realname), compressed_fileobj)
compressed_fileobj.seek(0)
with destream.open(
fileobj=compressed_fileobj, closefd=False) as archive:
# check that the decompressor has been used
Expand Down Expand Up @@ -226,7 +231,7 @@ def test_20_external_pipe_zstd(self):
uncompressed = BytesIO(b"Hello World\n")
uncompressed.name = 'test_file'
raw = BytesIO(
b'%\xb5/\xfd\x08@\x00\x0cHello World\n\xc0\x00\x00')
b'(\xb5/\xfd$\x0ca\x00\x00Hello World\n\x93C\x0f\x1a')
raw.name = "test_file.zst"
self._check_decompressor(
destream.decompressors.Unzstd,
Expand Down

0 comments on commit 18aba2b

Please sign in to comment.