Skip to content
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Changes in this branch:
- Support for Amiga protection bits
- Support for archive create system

Upstream README:



# LHA archive support for Python

The `lhafile` package is a python extension that handles .lha archives, with
Expand Down
24 changes: 23 additions & 1 deletion lhafile/lhafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ def _RealGetContent(self):
filename, crc = unpack('<%dsH' % filename_length, fp.read(filename_length + 2))
if os_level == 0:
ext_header_size = 0
os_identifier = None
pass
elif os_level == 1:
extra_data_size = header_size - (5+4+4+2+2+1+1+1+filename_length+2+1+2)
os_identifier, extra_data, ext_header_size \
= unpack('<c%dsH' % extra_data_size, fp.read(1 + extra_data_size + 2))
= unpack('<B%dsH' % extra_data_size, fp.read(1 + extra_data_size + 2))
sum_ext_header_size = 0
directory = None
comment = None
Expand Down Expand Up @@ -306,6 +307,25 @@ def _RealGetContent(self):
directory = directory.decode("ISO-8859-1")
directory = os.sep.join(directory.split('\xff'))
filename = os.path.join(directory, filename)

# OSIDs based on
# http://dangan.g.dgdg.jp/en/Content/Program/Java/jLHA/Notes/OSID.html
os_identifiers = { 0x41: 'Amiga', 0x4D: 'MS-DOS', 0x32: 'OS/2', 0x39: 'OS-9',
0x4B: 'OS/68K', 0x33: 'OS/386', 0x48: 'Human68K', 0x55: 'UNIX',
0x43: 'CP/M', 0x46: 'FLEX', 0x6D: 'Macintosh', 0x52: 'Runser',
0x54: 'TownOS', 0x58: 'XOSK', 0x77: 'Windows95', 0x57: 'WindowsNT',
0x00: 'generic/MS-DOS', 0x4A: 'Java' }
create_system = os_identifiers.get(os_identifier, '')

# set protection bits for Amiga archives
if create_system == 'Amiga' or ( os_level == 0 and reserved not in (0x20, 0x80) ):
flag_bits_bin = bin(reserved ^ 0b00001111)[2:].zfill(8)
default_flags = 'hsparwed'
flag_bits = ''.join([ flag[1] if flag[0] == '1' else '-' for flag in zip(
flag_bits_bin, default_flags)])
else:
flag_bits = None

info.directory = directory
info.filename = filename
info.compress_size = compress_size
Expand All @@ -319,6 +339,8 @@ def _RealGetContent(self):
info.comment = comment
info.compress_type = signature
info.date_time = date_time
info.create_system = create_system
info.flag_bits = flag_bits

if "\x00" in info.filename:
info.filename, info.comment = info.filename.split("\x00")
Expand Down