{"id":19649414,"url":"https://github.com/changaco/python-libarchive-c","last_synced_at":"2025-05-15T10:06:14.349Z","repository":{"id":19537450,"uuid":"22785341","full_name":"Changaco/python-libarchive-c","owner":"Changaco","description":"Python interface to libarchive","archived":false,"fork":false,"pushed_at":"2025-04-23T16:02:48.000Z","size":310,"stargazers_count":77,"open_issues_count":15,"forks_count":37,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-15T10:05:13.326Z","etag":null,"topics":["ctypes","libarchive","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Changaco.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"liberapay":"Changaco"}},"created_at":"2014-08-09T12:05:20.000Z","updated_at":"2025-04-23T21:39:40.000Z","dependencies_parsed_at":"2025-03-24T07:02:07.761Z","dependency_job_id":"72af0eb2-882e-4821-9287-8f0609d9a5f2","html_url":"https://github.com/Changaco/python-libarchive-c","commit_stats":{"total_commits":193,"total_committers":28,"mean_commits":6.892857142857143,"dds":"0.33160621761658027","last_synced_commit":"cbc7e0ac10feadc66b0297463e19b9e946fa5fe9"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Changaco%2Fpython-libarchive-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Changaco%2Fpython-libarchive-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Changaco%2Fpython-libarchive-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Changaco%2Fpython-libarchive-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Changaco","download_url":"https://codeload.github.com/Changaco/python-libarchive-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ctypes","libarchive","python"],"created_at":"2024-11-11T14:54:24.976Z","updated_at":"2025-05-15T10:06:14.308Z","avatar_url":"https://github.com/Changaco.png","language":"Python","funding_links":["https://liberapay.com/Changaco"],"categories":[],"sub_categories":[],"readme":"A Python interface to libarchive. It uses the standard ctypes_ module to\ndynamically load and access the C library.\n\n.. _ctypes: https://docs.python.org/3/library/ctypes.html\n\nInstallation\n============\n\n    pip install libarchive-c\n\nCompatibility\n=============\n\npython\n------\n\npython-libarchive-c is currently tested with python 3.12 and 3.13.\n\nIf you find an incompatibility with older versions you can send us a small patch,\nbut we won't accept big changes.\n\nlibarchive\n----------\n\npython-libarchive-c may not work properly with obsolete versions of libarchive such as the ones included in MacOS. In that case you can install a recent version of libarchive (e.g. with ``brew install libarchive`` on MacOS) and use the ``LIBARCHIVE`` environment variable to point python-libarchive-c to it::\n\n    export LIBARCHIVE=/usr/local/Cellar/libarchive/3.3.3/lib/libarchive.13.dylib\n\nUsage\n=====\n\nImport::\n\n    import libarchive\n\nExtracting archives\n-------------------\n\nTo extract an archive, use the ``extract_file`` function::\n\n    os.chdir('/path/to/target/directory')\n    libarchive.extract_file('test.zip')\n\nAlternatively, the ``extract_memory`` function can be used to extract from a buffer,\nand ``extract_fd`` from a file descriptor.\n\nThe ``extract_*`` functions all have an integer ``flags`` argument which is passed\ndirectly to the C function ``archive_write_disk_set_options()``. You can import\nthe ``EXTRACT_*`` constants from the ``libarchive.extract`` module and see the\nofficial description of each flag in the ``archive_write_disk(3)`` man page.\n\nBy default, when the ``flags`` argument is ``None``, the ``SECURE_NODOTDOT``,\n``SECURE_NOABSOLUTEPATHS`` and ``SECURE_SYMLINKS`` flags are passed to\nlibarchive, unless the current directory is the root (``/``).\n\nReading archives\n----------------\n\nTo read an archive, use the ``file_reader`` function::\n\n    with libarchive.file_reader('test.7z') as archive:\n        for entry in archive:\n            for block in entry.get_blocks():\n                ...\n\nAlternatively, the ``memory_reader`` function can be used to read from a buffer,\n``fd_reader`` from a file descriptor, ``stream_reader`` from a stream object\n(which must support the standard ``readinto`` method), and ``custom_reader``\nfrom anywhere using callbacks.\n\nTo learn about the attributes of the ``entry`` object, see the ``libarchive/entry.py``\nsource code or run ``help(libarchive.entry.ArchiveEntry)`` in a Python shell.\n\nDisplaying progress\n~~~~~~~~~~~~~~~~~~~\n\nIf your program processes large archives, you can keep track of its progress\nwith the ``bytes_read`` attribute. Here's an example of a progress bar using\n`tqdm \u003chttps://pypi.org/project/tqdm/\u003e`_::\n\n    with tqdm(total=os.stat(archive_path).st_size, unit='bytes') as pbar, \\\n         libarchive.file_reader(archive_path) as archive:\n        for entry in archive:\n            ...\n            pbar.update(archive.bytes_read - pbar.n)\n\nCreating archives\n-----------------\n\nTo create an archive, use the ``file_writer`` function::\n\n    from libarchive.entry import FileType\n\n    with libarchive.file_writer('test.tar.gz', 'ustar', 'gzip') as archive:\n        # Add the `libarchive/` directory and everything in it (recursively),\n        # then the `README.rst` file.\n        archive.add_files('libarchive/', 'README.rst')\n        # Add a regular file defined from scratch.\n        data = b'foobar'\n        archive.add_file_from_memory('../escape-test', len(data), data)\n        # Add a directory defined from scratch.\n        early_epoch = (42, 42)  # 1970-01-01 00:00:42.000000042\n        archive.add_file_from_memory(\n            'metadata-test', 0, b'',\n            filetype=FileType.DIRECTORY, permission=0o755, uid=4242, gid=4242,\n            atime=early_epoch, mtime=early_epoch, ctime=early_epoch, birthtime=early_epoch,\n        )\n\nAlternatively, the ``memory_writer`` function can be used to write to a memory buffer,\n``fd_writer`` to a file descriptor, and ``custom_writer`` to a callback function.\n\nFor each of those functions, the mandatory second argument is the archive format,\nand the optional third argument is the compression format (called “filter” in\nlibarchive). The acceptable values are listed in ``libarchive.ffi.WRITE_FORMATS``\nand ``libarchive.ffi.WRITE_FILTERS``.\n\nSymbolic links\n~~~~~~~~~~~~~~\n\nBy default, libarchive preserves symbolic links. If you want it to resolve the\nlinks and archive the files they point to instead, pass ``symlink_mode='logical'``\nwhen calling the ``add_files`` method. If you do that, an ``ArchiveError``\nexception will be raised when a symbolic link points to a nonexistent file.\n\nFile metadata codecs\n--------------------\n\nBy default, UTF-8 is used to read and write file attributes from and to archives.\nA different codec can be specified through the ``header_codec`` arguments of the\n``*_reader`` and ``*_writer`` functions. Example::\n\n    with libarchive.file_writer('test.tar', 'ustar', header_codec='cp037') as archive:\n        ...\n    with file_reader('test.tar', header_codec='cp037') as archive:\n        ...\n\nIn addition to file paths (``pathname`` and ``linkpath``), the specified codec is\nused to encode and decode user and group names (``uname`` and ``gname``).\n\nLicense\n=======\n\n`CC0 Public Domain Dedication \u003chttp://creativecommons.org/publicdomain/zero/1.0/\u003e`_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchangaco%2Fpython-libarchive-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchangaco%2Fpython-libarchive-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchangaco%2Fpython-libarchive-c/lists"}