Are you looking to work with RISC OS Zip archives using Python? Look no further! In this article, we will explore the rozipinfo
and rozipfile
modules, which provide powerful functionalities for handling RISC OS Zip archives.
rozipinfo
Module
The rozipinfo
module provides decoding for the RISC OS specific extra fields in the Zip archives. It allows you to convert the standard zipfile.ZipInfo
objects into objects with RISC OS properties extracted from the Zip file’s extra field. Here are some important features of the rozipinfo
module:
- Supports reading RISC OS-style file properties, including the RISC OS format filename, date and time with centiseconds, object type (file or directory), load address, exec address, filetype number, and attributes value.
- Forces the filename to be unicode, decoded using the archive’s encoding.
- All properties are mutable, allowing the extra field to be regenerated and base properties to be updated.
- Supports reading and writing the extra field, as well as transferring to other platforms using the NFS filename encoding format.
- Provides configurability for encoding used for RISC OS filenames and filetype inference rules.
rozipfile
Module
Building on the rozipinfo
module, the rozipfile
module works similarly to the regular zipfile
module, but with additional functionality specific to RISC OS Zip archives. Here’s what you can do with the rozipfile
module:
- List files in the archive as they would appear in RISC OS.
- Create archives of files on Unix systems that are extractable on RISC OS, including filetypes.
- Extract files from the RISC OS format archive using the NFS filename encoding.
The module also includes a command line interface, allowing you to perform operations on RISC OS Zip archives directly from the command line. You can list archives, create new archives from files, extract files from archives, and even produce commands to restore filetypes from a badly extracted file.
Example Usage
To demonstrate the usage of these modules, let’s take a quick look at some code snippets:
“`python
import rozipinfo
import rozipfile
Read a RISC OS Zip archive
with rozipfile.RISCOSZipFile(‘ro-app.zip’, ‘r’) as zh:
zh.printdir()
Create a new RISC OS Zip archive
with rozipfile.RISCOSZipFile(‘newzip.zip’, ‘w’, base_dir=’.’) as rzh:
rzh.add_dir(‘!MyApp’)
rzh.add_file(‘!MyApp/!Run,feb’)
rzh.add_file(‘!MyApp/!Sprites,ff9’)
rzh.add_file(‘!MyApp/!RunImage,ffb’)
Extract files from a RISC OS Zip archive
with rozipfile.RISCOSZipFile(‘ro-app.zip’, ‘r’) as zh:
zh.extractall(path=’new-directory’)
“`
Command Line Usage
If you prefer working from the command line, the rozipfile
module has got you covered. Here are some examples of command line usage:
-
List contents of an archive:
bash
python -m rozipfile --list <archive> -
Create a new archive:
bash
python -m rozipfile [--chdir <dir>] --create <archive> <files>* -
Extract files from an archive:
bash
python -m rozipfile [--chdir <dir>] --extract <archive> <files>* -
Restore filetypes from a badly extracted file:
bash
python -m rozipfile [--chdir <dir>] --settypes <archive>
Conclusion
Handling RISC OS Zip archives is made easy with the rozipinfo
and rozipfile
modules in Python. Whether you need to extract files, create archives, or perform operations from the command line, these modules provide the necessary functionalities. So go ahead, give them a try and simplify your RISC OS Zip archive workflows!
References
Continue Reading:
– Introduction to Python ZipFile Module
– Exploring RISC OS: A Beginner’s Guide
– Optimizing Performance in Zip Archive Operations
Leave a Reply