Skip to content

Commit 18aba2b

Browse files
authored
Fixed CI & added Python 3.7
* 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
1 parent a9e12b4 commit 18aba2b

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ python:
44
- "3.4"
55
- "3.5"
66
- "3.6"
7+
- "3.7"
8+
9+
os:
10+
- linux
11+
# - osx # NOTE: Python is not available yet (not tested)
12+
# - windows # NOTE: Python is not available yet
713

814
cache: pip
915

1016
before_install:
1117
- sudo apt-get install p7zip rar
12-
- sudo sh -c 'echo "deb http://archive.ubuntu.com/ubuntu/ artful main restricted universe" > /etc/apt/sources.list'
18+
# NOTE: attempt to get a more updated version of file and libmagic >= 5.30
19+
- sudo sh -c 'echo "deb http://archive.ubuntu.com/ubuntu/ bionic main restricted universe" > /etc/apt/sources.list'
1320
- sudo apt-get update
1421
- sudo apt-get install zstd
1522
- sudo apt-get install file libmagic1

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ destream
66

77
_destream: decompress a stream_
88

9+
Compatibility
10+
-------------
11+
12+
* Python: 2.7, 3.4, 3.5, 3.6, 3.7
13+
* OS:
14+
- Linux
15+
- OSX is not tested
16+
- Windows is not tested and requires file and libmagic for Windows
17+
918
Installation
1019
------------
1120

@@ -52,15 +61,15 @@ Lib Usage
5261
assert isinstance(archive, destream.Archive)
5362
5463
# ==> we can read the content but not seek
55-
print archive.read()
64+
print(archive.read())
5665
```
5766
3. Open an archive that holds only one file,
5867
```python
5968
archive = destream.open("some_file.tar.xz")
6069
6170
# ==> we can read the archive like it is a stream
6271
if archive.single():
63-
print archive.read()
72+
print(archive.read())
6473
else:
6574
archive.extractall('/tmp/some/path/')
6675
```

destream/decompressors/rar.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212
__all__ = ['Unrar']
1313

1414

15-
def parse_hunk(hunk):
16-
info = {}
17-
for m in re.finditer(
18-
r'^[ \t\f]*(.+?)[ \t\f]*:[ \t\f]*(.*?)[ \t\f]*$',
19-
hunk, flags=re.M):
20-
key = re.sub(r'\W', '_', m.group(1).lower())
21-
info[key] = m.group(2)
22-
if info.get('service', '') == 'EOF':
23-
raise StopIteration()
24-
return info
15+
def iter_on_hunks(hunks):
16+
for hunk in hunks:
17+
info = {}
18+
for m in re.finditer(
19+
r'^[ \t\f]*(.+?)[ \t\f]*:[ \t\f]*(.*?)[ \t\f]*$',
20+
hunk, flags=re.M):
21+
key = re.sub(r'\W', '_', m.group(1).lower())
22+
info[key] = m.group(2)
23+
if info.get('service', '') == 'EOF':
24+
break
25+
yield info
2526

2627

2728
class Header(object):
28-
def __init__(self, hunk):
29-
self.__dict__.update(parse_hunk(hunk))
29+
def __init__(self, info):
30+
self.__dict__.update(info)
3031
assert 'RAR' in self.details, \
3132
"Maybe not a RAR file:%s\n" % self.details
3233

3334

3435
class Member(object):
35-
def __init__(self, hunk):
36-
info = parse_hunk(hunk)
36+
def __init__(self, info):
3737
info['filename'] = info.pop('name')
3838
info['size'] = int(info.get('size', 0))
3939
info['packed_size'] = int(info.get('packed_size', 0))
@@ -76,8 +76,8 @@ def __init__(self, name, fileobj):
7676
self.fileobj = ArchiveTemp(fileobj)
7777
output = check_output(self._command +
7878
['vta', self.fileobj.name]).decode()
79-
hunks = iter(output.split("\n\n"))
80-
self.information = next(hunks).strip()
79+
hunks = iter_on_hunks(output.split("\n\n"))
80+
self.information = next(hunks)
8181
self.header = Header(next(hunks))
8282
self._members = [m for m in (Member(h) for h in hunks)]
8383
self._stream = (len(self._members) == 1)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name = "destream",
5-
version = "4.2.0",
5+
version = "5.0.0",
66
author = "Cecile Tonglet",
77
author_email = "cecile.tonglet@gmail.com",
88
description = ("A simple module to decompress streams compressed multiple "
@@ -12,7 +12,7 @@
1212
url = "https://github.com/cecton/destream",
1313
packages = find_packages(),
1414
scripts = ['scripts/destream'],
15-
install_requires = ['python-magic==0.4.12'],
15+
install_requires = ['python-magic>=0.4.12'],
1616
classifiers = [
1717
"Development Status :: 5 - Production/Stable",
1818
"Topic :: System :: Archiving :: Compression",

tests/test_30_decompressors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from io import BytesIO
77
import tarfile
88
import zipfile
9+
import magic
910
try:
1011
import unittest2 as unittest
1112
except ImportError:
@@ -25,6 +26,10 @@ def _check_decompressor(self, decompressor, compressed_fileobj,
2526
self.skipTest("decompressor not available")
2627
if expected_name is None:
2728
expected_name = decompressed_fileobj.name
29+
archive = destream.ArchiveFile(compressed_fileobj, None, closefd=False)
30+
mime = magic.from_buffer(archive.peek(1024), mime=True)
31+
decompressor._guess(mime, str(archive.realname), compressed_fileobj)
32+
compressed_fileobj.seek(0)
2833
with destream.open(
2934
fileobj=compressed_fileobj, closefd=False) as archive:
3035
# check that the decompressor has been used
@@ -226,7 +231,7 @@ def test_20_external_pipe_zstd(self):
226231
uncompressed = BytesIO(b"Hello World\n")
227232
uncompressed.name = 'test_file'
228233
raw = BytesIO(
229-
b'%\xb5/\xfd\x08@\x00\x0cHello World\n\xc0\x00\x00')
234+
b'(\xb5/\xfd$\x0ca\x00\x00Hello World\n\x93C\x0f\x1a')
230235
raw.name = "test_file.zst"
231236
self._check_decompressor(
232237
destream.decompressors.Unzstd,

0 commit comments

Comments
 (0)