|
| 1 | +# Libarx |
| 2 | + |
| 3 | +`libarx` module allows you to read and write Arx |
| 4 | +archives in Python. It provides a shallow python |
| 5 | +interface on top of the [Rust `libarx` library](https://github.com/jubako/arx). |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```sh |
| 10 | +pip install libarx |
| 11 | +``` |
| 12 | + |
| 13 | +Our [PyPI wheels](https://pypi.org/project/libarx/) bundle the Rust libarx and are available for the following platforms: |
| 14 | + |
| 15 | +- macOS for `x86_64` |
| 16 | +- GNU/Linux for `x86_64` |
| 17 | +- Windows for `x64` |
| 18 | + |
| 19 | +Wheels are available for CPython only. |
| 20 | + |
| 21 | +Users on other platforms can install the source distribution (see [Building](#Building) below). |
| 22 | + |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +### Read an Arx archive |
| 27 | + |
| 28 | +```python |
| 29 | +from libarx import Arx |
| 30 | + |
| 31 | +archive = Arx("my_archive.arx") |
| 32 | +entry = arx.get_entry("foo/bar") |
| 33 | + |
| 34 | +print(f"Entry (idx: {entry.idx}) name is {entry.path}") |
| 35 | +if entry.is_file(): |
| 36 | + print("Entry is a file"). |
| 37 | + content = entry.get_content() |
| 38 | + print(content) |
| 39 | +elif entry.is_link(): |
| 40 | + print(f"Entry is a link pointing to {entry.get_target()}") |
| 41 | +else: |
| 42 | + print("Entry is a directory.") |
| 43 | + print(f"children are ranged from {entry.first_child()} to {entry.first_child()+entry.nb_children()}") |
| 44 | + |
| 45 | +# We can also iterate on entries in arx |
| 46 | +def iterate(iterable, root=""): |
| 47 | + for entry in iterable: |
| 48 | + path = root + "/" + entry.pathi |
| 49 | + if entry.is_file(): |
| 50 | + content = entry.get_content()[..512] |
| 51 | + print(f"File {path} : {content}") |
| 52 | + elif entry.is_link(): |
| 53 | + print(f"Link {path} -> {entry.get_target()}") |
| 54 | + else: |
| 55 | + print(f"Dir {path}") |
| 56 | + iterate(entry, path) |
| 57 | + |
| 58 | +iterate(arx) |
| 59 | + |
| 60 | + |
| 61 | +# Arx archive can simply be extracted with : |
| 62 | +arx.extract("target/directory/where/to/extract") |
| 63 | +``` |
| 64 | + |
| 65 | +### Create an Arx archive |
| 66 | + |
| 67 | +```python |
| 68 | +from libarx import Creator |
| 69 | + |
| 70 | +with Creator("my_archive.arx") as creator: |
| 71 | + creator.add("path/to/entry/to/add", recursive=(False or True)) |
| 72 | +``` |
| 73 | + |
| 74 | +## Building |
| 75 | + |
| 76 | +Python `libarx` is compiled using [maturin](https://www.maturin.rs/) |
| 77 | + |
| 78 | +- Install rust (https://www.rust-lang.org/learn/get-started) |
| 79 | +- Install python |
| 80 | +- Install maturin : `pip install maturin` |
| 81 | +- Build everything : `maturin build` |
| 82 | + |
| 83 | +## License |
| 84 | + |
| 85 | +[MIT](https://mit-license.org/) |
| 86 | + |
| 87 | + |
| 88 | +## Support |
| 89 | + |
| 90 | +libarx, Arx and all Jubako project is developed on my spare time. If you liked it, please |
| 91 | +consider sponsor me. At your convinence: (Github)[https://github.com/sponsors/jubako], |
| 92 | +(liberapay)[https://liberapay.com/jubako/donate] or (buy me a coffe)[https://buymeacoffee.com/jubako] |
0 commit comments