How to use the extractcode.libarchive2 function in extractcode

To help you get started, we’ve selected a few extractcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nexB / scancode-toolkit / tests / extractcode / test_extract.py View on Github external
def test_uncompress_corrupted_archive_with_libarchive(self):
        from extractcode import libarchive2
        from commoncode import compat
        test_dir = self.get_test_loc('extract/corrupted/a.tar.gz', copy=True)
        target_dir = self.get_temp_dir()
        try:
            list(libarchive2.extract(test_dir, target_dir))
            raise Exception('no error raised')
        except libarchive2.ArchiveError as e:
            emsg = str(e)
            assert 'gzip decompression failed' == emsg
            if py3:
                assert isinstance(emsg, compat.unicode)
github nexB / scancode-toolkit / tests / extractcode / test_extract.py View on Github external
def test_uncompress_corrupted_archive_with_libarchive(self):
        from extractcode import libarchive2
        from commoncode import compat
        test_dir = self.get_test_loc('extract/corrupted/a.tar.gz', copy=True)
        target_dir = self.get_temp_dir()
        try:
            list(libarchive2.extract(test_dir, target_dir))
            raise Exception('no error raised')
        except libarchive2.ArchiveError as e:
            emsg = str(e)
            assert 'gzip decompression failed' == emsg
            if py3:
                assert isinstance(emsg, compat.unicode)
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
def test_extract_zip_with_trailing_data2(self):
        # test archive created on cygwin with:
        # $ echo "test content" > f1
        # $ zip test f1
        # $ echo "some junk" >> test.zip
        test_file = self.get_test_loc('archive/zip/zip_trailing_data2.zip')
        test_dir = self.get_temp_dir()
        try:
            archive.extract_zip(test_file, test_dir)
        except libarchive2.ArchiveError, ae:
            assert 'Invalid central directory signature' in str(ae)
        # fails because of https://github.com/libarchive/libarchive/issues/545
        result = os.path.join(test_dir, 'f1')
        assert os.path.exists(result)
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
def test_extract_tar_with_weird_filenames_with_libarchive(self):
        test_file = self.get_test_loc('archive/weird_names/weird_names.tar')
        self.check_extract(libarchive2.extract, test_file, expected_warnings=[], expected_suffix='libarch')
github nexB / scancode-toolkit / tests / extractcode / test_archive.py View on Github external
def test_extract_zip_with_trailing_data(self):
        test_file = self.get_test_loc('archive/zip/zip_trailing_data.zip')
        test_dir = self.get_temp_dir()
        try:
            archive.extract_zip(test_file, test_dir)
        except libarchive2.ArchiveError, ae:
            assert 'Invalid central directory signature' in str(ae)

        # fails because of https://github.com/libarchive/libarchive/issues/545
        result = os.path.join(test_dir, 'a.txt')
        assert os.path.exists(result)
github nexB / scancode-toolkit / src / extractcode / archive.py View on Github external
extract_ar = libarchive2.extract
extract_msi = sevenzip.extract
extract_cpio = libarchive2.extract

# sevenzip should be best at extracting 7zip but most often libarchive is better first
extract_7z = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

# libarchive is best for the run of the mill zips, but sevenzip sometimes is better
extract_zip = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

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

extract_lzip = libarchive2.extract

extract_iso = sevenzip.extract
extract_rar = libarchive2.extract
extract_rpm = sevenzip.extract
extract_xz = sevenzip.extract
extract_lzma = sevenzip.extract
extract_squashfs = sevenzip.extract
extract_cab = sevenzip.extract
extract_nsis = sevenzip.extract
extract_ishield = sevenzip.extract
extract_Z = sevenzip.extract
extract_xarpkg = sevenzip.extract

# Archive handlers.
####################

TarHandler = Handler(
    name='Tar',
    filetypes=('.tar', 'tar archive',),
github nexB / scancode-toolkit / src / extractcode / archive.py View on Github external
try:
        warnings = extractor(abs_location, temp_target)
        if TRACE:
            logger.debug('try_to_extract: temp_target: %(temp_target)r' % locals())
        fileutils.copytree(temp_target, abs_target_dir)
    except:
        return warnings
    finally:
        fileutils.delete(temp_target)
    return warnings

# High level aliases to lower level extraction functions
########################################################


extract_tar = libarchive2.extract
extract_patch = patch.extract

extract_deb = libarchive2.extract
extract_ar = libarchive2.extract
extract_msi = sevenzip.extract
extract_cpio = libarchive2.extract

# sevenzip should be best at extracting 7zip but most often libarchive is better first
extract_7z = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

# libarchive is best for the run of the mill zips, but sevenzip sometimes is better
extract_zip = functional.partial(extract_with_fallback, extractor1=libarchive2.extract, extractor2=sevenzip.extract)

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

extract_lzip = libarchive2.extract