class documentation

The header of a ZIM file.

The header contains various metadata informations about the ZIM file as well as the offsets of some other datastructures in the ZIM file.

Class Method from_bytes Construct a header from a bytestring.
Class Method from_file Read the header from a file.
Class Method placeholder Generate a placeholder header and return it.
Method __init__ The default constructor.
Method __str__ Return a string displaying the content of the header.
Method check_compatible Check if this header is compatible, raising an exception if not.
Method checksum_position.setter The offset to the checksum.
Method cluster_count.setter The number of clusters in this archive.
Method cluster_pointer_position.setter The offset to the cluster pointer list.
Method entry_count.setter The number of entries in this archive.
Method get_disk_size Calculate the size of this object when written to a file.
Method layout_page.setter The index of the layout page in the url pointer list, None if not present.
Method magic_number.setter The magic number of this ZIM file.
Method main_page.setter The index of the main page in the url pointer list, None if not present.
Method major_version.setter The major version of this ZIM file.
Method mime_list_position.setter The offset to the mime type list.
Method minor_version.setter The minor version of this ZIM file.
Method title_pointer_position.setter The offset to the directory pointer list ordered by title.
Method to_bytes Dump this header into a bytestring.
Method to_dict Dump this header into a dictionary and return it.
Method url_pointer_position.setter The offset to the directory pointer list ordered by URL.
Method uuid.setter The UUID of this ZIM file.
Constant FORMAT the format of a ZIM header
Constant LENGTH length of the ZIM header
Constant MAGIC_NUMBER the magic number used to identify ZIM files.
Property checksum_position The offset to the checksum.
Property cluster_count The number of clusters in this archive.
Property cluster_pointer_position The offset to the cluster pointer list.
Property entry_count The number of entries in this archive.
Property has_layout_page A boolean indicating whether this header knows the position of the layout page or not.
Property has_main_page A boolean indicating whether this header knows the position of the main page or not.
Property layout_page The index of the layout page in the url pointer list, None if not present.
Property magic_number The magic number of this ZIM file.
Property main_page The index of the main page in the url pointer list, None if not present.
Property major_version The major version of this ZIM file.
Property mime_list_position The offset to the mime type list.
Property minor_version The minor version of this ZIM file.
Property title_pointer_position The offset to the directory pointer list ordered by title.
Property url_pointer_position The offset to the directory pointer list ordered by URL.
Property uuid The UUID of this ZIM file.
Instance Variable _checksum_position offset to the checksum
Instance Variable _cluster_count number of clusters in the archive
Instance Variable _cluster_pointer_position offset to the cluster pointer list
Instance Variable _entry_count number of entries in the archive
Instance Variable _layout_page index of the layout page in the url pointer list, 0xffffffff if not present
Instance Variable _magic_number magic number of this ZIM file.
Instance Variable _main_page index of the main page in the url pointer list, 0xffffffff if not present
Instance Variable _major_version the major version of this ZIM file
Instance Variable _mime_list_position offset to the mime type list
Instance Variable _minor_version the minor version of this ZIM file
Instance Variable _title_pointer_position offset tot he directory pointer list ordered by title
Instance Variable _url_pointer_position offset to the directory pointer list ordered by URL
Instance Variable _uuid uuid of the ZIM file

Inherited from ModifiableMixIn:

Method add_submodifiable Add another modifiable object as a child of this one.
Method after_flush_or_read This method should be called after this object has been read and/or flushed to disk. In other words, it should be called at least once whenever this object matches the state of the object on the disk.
Method dirty.setter Setter for ModifiableMixIn.dirty
Method ensure_mutable If this object is non-mutable, raise an Exception.
Method get_initial_disk_size Return the size of this object on disk as it has been read.
Method get_unmodified_disk_size Return the size of this object when written to a file before any modifications has been made since the last read/flush.
Method mark_dirty Convenience function to mark this object as dirty.
Method remove_submodifiable Remove a submodifiable from this object.
Instance Variable dirty True if this object or a sub-modifiable has been modified.
Instance Variable mutable if not nonzero, prevent modifications of this object.
Instance Variable _dirty a boolean flag that's nonzero if this object has been modified
Instance Variable _old_disk_size the size of this object on disk before any modifications since the last flush/read
Instance Variable _submodifiables a list of child objects, whose dirty state will affect this objects dirty state.
def from_bytes(cls, s):

Construct a header from a bytestring.

Parameters
s:bytesstring to parse
Returns
pyzim.header.Headerthe header parsed from the bytes
def from_file(cls, f, seek=None):

Read the header from a file.

Parameters
f:file-likefile-like object to read from
seek:int or Noneif specified, seek this position of the file before reading
Returns
pyzim.header.Headerthe header read from the file
def placeholder(cls):

Generate a placeholder header and return it.

A placeholder header is a header populated with some reasonable defaults as well as placeholder values. It is not usable for an actual ZIM file, but has the correct length. This makes it useful as part of the ZIM creation process.

Returns
Headera placeholder header
def __init__(self, magic_number, major_version, minor_version, uuid, entry_count, cluster_count, url_pointer_position, title_pointer_position, cluster_pointer_position, mime_list_position, main_page, layout_page, checksum_position):

The default constructor.

The arguments are arranged in the same order as they appear in the ZIM header. This allows directly unpacking the header string into this constructor.

Parameters
magic_number:intmagic number of this ZIM file. If set to None (recommended), use default.
major_version:intthe major version of this ZIM file
minor_version:intthe minor version of this ZIM file
uuid:int or bytes or uuid.UUIDuuid of the ZIM file
entry_count:intnumber of entries in the archive
cluster_count:intnumber of clusters in the archive
url_pointer_position:intoffset to the directory pointer list ordered by URL
title_pointer_position:intoffset tot he directory pointer list ordered by title
cluster_pointer_position:intoffset to the cluster pointer list
mime_list_position:intoffset to the mime type list
main_page:intindex of the main page in the url pointer list, 0xffffffff if not present
layout_page:intindex of the layout page in the url pointer list, 0xffffffff if not present
checksum_position:intoffset to the checksum
def __str__(self):

Return a string displaying the content of the header.

Returns
stra string describing the header
def check_compatible(self):

Check if this header is compatible, raising an exception if not.

Raises
pyzim.exceptions.NotAZimFilewhen the provided file is not a ZIM file.
pyzim.exceptions.IncompatibleZimFilewhen the ZIM file is not compatible
def checksum_position(self, value):

The offset to the checksum.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def cluster_count(self, value):

The number of clusters in this archive.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def cluster_pointer_position(self, value):

The offset to the cluster pointer list.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def entry_count(self, value):

The number of entries in this archive.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def get_disk_size(self):

Calculate the size of this object when written to a file.

NOTE: in this context, size refers to the direct size of the object. If this object contains references to other objects, their sizes will not be included. For example, a pyzim.entry.ContentEntry also links to a blob, but this function will only return the size of the entry itself, excluding the referenced blob.

Returns
intthe size, in bytes
def layout_page(self, value):

The index of the layout page in the url pointer list, None if not present.

Parameters
value:int or Nonevalue to set
Raises
TypeErrorif value is not an integer nor None
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def magic_number(self, value):

The magic number of this ZIM file.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
def main_page(self, value):

The index of the main page in the url pointer list, None if not present.

Parameters
value:int or Nonevalue to set
Raises
TypeErrorif value is not an integer nor None
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def major_version(self, value):

The major version of this ZIM file.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative).
def mime_list_position(self, value):

The offset to the mime type list.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def minor_version(self, value):

The minor version of this ZIM file.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative).
def title_pointer_position(self, value):

The offset to the directory pointer list ordered by title.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def to_bytes(self):

Dump this header into a bytestring.

Returns
bytesa bytestring representation of this header.
def to_dict(self):

Dump this header into a dictionary and return it.

Some values may be converted.

Returns
dicta dictionary containing the information in this header
def url_pointer_position(self, value):

The offset to the directory pointer list ordered by URL.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def uuid(self, value):

The UUID of this ZIM file.

Parameters
value:int or bytes or uuid.UUIDvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this header is set to be inmutable.
FORMAT: str =

the format of a ZIM header

Value
constants.ENDIAN + 'IHH16sIIQQQQIIQ'
LENGTH: int =

length of the ZIM header

Value
struct.calcsize(FORMAT)
MAGIC_NUMBER: int =

the magic number used to identify ZIM files.

Value
72173914
checksum_position: int =

The offset to the checksum.

cluster_count: int =

The number of clusters in this archive.

cluster_pointer_position: int =

The offset to the cluster pointer list.

entry_count: int =

The number of entries in this archive.

has_layout_page: bool =

A boolean indicating whether this header knows the position of the layout page or not.

has_main_page: bool =

A boolean indicating whether this header knows the position of the main page or not.

layout_page: int or None =

The index of the layout page in the url pointer list, None if not present.

magic_number: int =

The magic number of this ZIM file.

main_page: int or None =

The index of the main page in the url pointer list, None if not present.

major_version: int =

The major version of this ZIM file.

mime_list_position: int =

The offset to the mime type list.

minor_version: int =

The minor version of this ZIM file.

title_pointer_position: int =

The offset to the directory pointer list ordered by title.

url_pointer_position: int =

The offset to the directory pointer list ordered by URL.

The UUID of this ZIM file.

_checksum_position: int =

offset to the checksum

_cluster_count: int =

number of clusters in the archive

_cluster_pointer_position: int =

offset to the cluster pointer list

_entry_count: int =

number of entries in the archive

_layout_page: int =

index of the layout page in the url pointer list, 0xffffffff if not present

_magic_number: int =

magic number of this ZIM file.

_main_page: int =

index of the main page in the url pointer list, 0xffffffff if not present

_major_version: int =

the major version of this ZIM file

_mime_list_position: int =

offset to the mime type list

_minor_version: int =

the minor version of this ZIM file

_title_pointer_position: int =

offset tot he directory pointer list ordered by title

_url_pointer_position: int =

offset to the directory pointer list ordered by URL

_uuid: uuid.UUID =

uuid of the ZIM file