Skip to content

Commit 263849f

Browse files
committed
Extract lzip files #245 #989
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 121faaf commit 263849f

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

src/extractcode/archive.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ def try_to_extract(location, target_dir, extractor):
423423

424424
extract_springboot = functional.partial(try_to_extract, extractor=extract_zip)
425425

426+
extract_lzip = libarchive2.extract
427+
426428
extract_iso = sevenzip.extract
427429
extract_rar = libarchive2.extract
428430
extract_rpm = sevenzip.extract
@@ -655,6 +657,16 @@ def try_to_extract(location, target_dir, extractor):
655657
strict=False
656658
)
657659

660+
TarLzipHandler = Handler(
661+
name='Tar lzip',
662+
filetypes=('lzip compressed',),
663+
mimetypes=('application/x-lzip',) ,
664+
extensions=('.tar.lz',),
665+
kind=regular_nested,
666+
extractors=[extract_lzip, extract_tar],
667+
strict=False
668+
)
669+
658670
# https://wiki.openwrt.org/doc/techref/opkg: ipk
659671
# http://downloads.openwrt.org/snapshots/trunk/x86/64/packages/base/
660672

@@ -678,6 +690,16 @@ def try_to_extract(location, target_dir, extractor):
678690
strict=False
679691
)
680692

693+
LzipHandler = Handler(
694+
name='lzip',
695+
filetypes=('lzip compressed',),
696+
mimetypes=('application/x-lzip',) ,
697+
extensions=('.lzip',),
698+
kind=regular,
699+
extractors=[extract_lzip],
700+
strict=False
701+
)
702+
681703
DiaDocHandler = Handler(
682704
name='Dia diagram doc',
683705
filetypes=('gzip compressed',),
201 Bytes
Binary file not shown.
43 Bytes
Binary file not shown.

tests/extractcode/test_archive.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,22 @@ def test_extract_cbz_basic_with_weird_filename_extension(self):
22872287
assert expected == extracted
22882288

22892289

2290+
class TestLzip(BaseArchiveTestCase):
2291+
2292+
def test_extract_tarlzip_basic(self):
2293+
test_file = self.get_test_loc('archive/lzip/sample.tar.lz')
2294+
test_dir = self.get_temp_dir()
2295+
archive.extract_tar(test_file, test_dir)
2296+
result = os.path.join(test_dir, 'tst')
2297+
assert ['empty', 'some'] == sorted(os.listdir(result))
2298+
2299+
def test_uncompress_lzip_basic(self):
2300+
test_file = self.get_test_loc('archive/lzip/some.lz')
2301+
test_dir = self.get_temp_dir()
2302+
archive.extract_lzip(test_file, test_dir)
2303+
assert ['dfsdfsdfsdfsdfsdfsd_'] == os.listdir(test_dir)
2304+
2305+
22902306
################################################################################
22912307
# Note: The following series of test is not easy to grasp but unicode archives
22922308
# on multiple OS are hard to tests. So we have one test class for each

0 commit comments

Comments
 (0)