class Header(ModifiableMixIn):
Constructor: Header(magic_number, major_version, minor_version, uuid, ...)
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 |
Construct a header from a bytestring. |
| Class Method | from |
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 |
Check if this header is compatible, raising an exception if not. |
| Method | checksum |
The offset to the checksum. |
| Method | cluster |
The number of clusters in this archive. |
| Method | cluster |
The offset to the cluster pointer list. |
| Method | entry |
The number of entries in this archive. |
| Method | get |
Calculate the size of this object when written to a file. |
| Method | layout |
The index of the layout page in the url pointer list, None if not present. |
| Method | magic |
The magic number of this ZIM file. |
| Method | main |
The index of the main page in the url pointer list, None if not present. |
| Method | major |
The major version of this ZIM file. |
| Method | mime |
The offset to the mime type list. |
| Method | minor |
The minor version of this ZIM file. |
| Method | title |
The offset to the directory pointer list ordered by title. |
| Method | to |
Dump this header into a bytestring. |
| Method | to |
Dump this header into a dictionary and return it. |
| Method | url |
The offset to the directory pointer list ordered by URL. |
| Method | uuid |
The UUID of this ZIM file. |
| Constant | FORMAT |
the format of a ZIM header |
| Constant | LENGTH |
length of the ZIM header |
| Constant | MAGIC |
the magic number used to identify ZIM files. |
| Property | checksum |
The offset to the checksum. |
| Property | cluster |
The number of clusters in this archive. |
| Property | cluster |
The offset to the cluster pointer list. |
| Property | entry |
The number of entries in this archive. |
| Property | has |
A boolean indicating whether this header knows the position of the layout page or not. |
| Property | has |
A boolean indicating whether this header knows the position of the main page or not. |
| Property | layout |
The index of the layout page in the url pointer list, None if not present. |
| Property | magic |
The magic number of this ZIM file. |
| Property | main |
The index of the main page in the url pointer list, None if not present. |
| Property | major |
The major version of this ZIM file. |
| Property | mime |
The offset to the mime type list. |
| Property | minor |
The minor version of this ZIM file. |
| Property | title |
The offset to the directory pointer list ordered by title. |
| Property | url |
The offset to the directory pointer list ordered by URL. |
| Property | uuid |
The UUID of this ZIM file. |
| Instance Variable | _checksum |
offset to the checksum |
| Instance Variable | _cluster |
number of clusters in the archive |
| Instance Variable | _cluster |
offset to the cluster pointer list |
| Instance Variable | _entry |
number of entries in the archive |
| Instance Variable | _layout |
index of the layout page in the url pointer list, 0xffffffff if not present |
| Instance Variable | _magic |
magic number of this ZIM file. |
| Instance Variable | _main |
index of the main page in the url pointer list, 0xffffffff if not present |
| Instance Variable | _major |
the major version of this ZIM file |
| Instance Variable | _mime |
offset to the mime type list |
| Instance Variable | _minor |
the minor version of this ZIM file |
| Instance Variable | _title |
offset tot he directory pointer list ordered by title |
| Instance Variable | _url |
offset to the directory pointer list ordered by URL |
| Instance Variable | _uuid |
uuid of the ZIM file |
Inherited from ModifiableMixIn:
| Method | add |
Add another modifiable object as a child of this one. |
| Method | after |
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 for ModifiableMixIn.dirty |
| Method | ensure |
If this object is non-mutable, raise an Exception. |
| Method | get |
Return the size of this object on disk as it has been read. |
| Method | get |
Return the size of this object when written to a file before any modifications has been made since the last read/flush. |
| Method | mark |
Convenience function to mark this object as dirty. |
| Method | remove |
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 |
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. |
Construct a header from a bytestring.
| Parameters | |
s:bytes | string to parse |
| Returns | |
pyzim.header.Header | the header parsed from the bytes |
Read the header from a file.
| Parameters | |
| f:file-like | file-like object to read from |
seek:int or None | if specified, seek this position of the file before reading |
| Returns | |
pyzim.header.Header | the header read from the file |
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 | |
Header | a placeholder header |
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 | |
magicint | magic number of this ZIM file. If set to None (recommended), use default. |
majorint | the major version of this ZIM file |
minorint | the minor version of this ZIM file |
uuid:int or bytes or uuid.UUID | uuid of the ZIM file |
entryint | number of entries in the archive |
clusterint | number of clusters in the archive |
urlint | offset to the directory pointer list ordered by URL |
titleint | offset tot he directory pointer list ordered by title |
clusterint | offset to the cluster pointer list |
mimeint | offset to the mime type list |
mainint | index of the main page in the url pointer list, 0xffffffff if not present |
layoutint | index of the layout page in the url pointer list, 0xffffffff if not present |
checksumint | offset to the checksum |
Check if this header is compatible, raising an exception if not.
| Raises | |
pyzim.exceptions.NotAZimFile | when the provided file is not a ZIM file. |
pyzim.exceptions.IncompatibleZimFile | when the ZIM file is not compatible |
The offset to the checksum.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The number of clusters in this archive.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The offset to the cluster pointer list.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The number of entries in this archive.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
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 | |
int | the size, in bytes |
The index of the layout page in the url pointer list, None if not present.
| Parameters | |
value:int or None | value to set |
| Raises | |
TypeError | if value is not an integer nor None |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The magic number of this ZIM file.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
The index of the main page in the url pointer list, None if not present.
| Parameters | |
value:int or None | value to set |
| Raises | |
TypeError | if value is not an integer nor None |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The major version of this ZIM file.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative). |
The offset to the mime type list.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The minor version of this ZIM file.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative). |
The offset to the directory pointer list ordered by title.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
Dump this header into a dictionary and return it.
Some values may be converted.
| Returns | |
dict | a dictionary containing the information in this header |
The offset to the directory pointer list ordered by URL.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The UUID of this ZIM file.
| Parameters | |
value:int or bytes or uuid.UUID | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this header is set to be inmutable. |