class ContentEntry(BaseEntry):
Constructor: ContentEntry(mimetype, namespace, revision, cluster_number, ...)
An entry for actual content (e.g. an article).
| Class Method | from |
Read a content entry from a file. |
| Method | __init__ |
The default constructor. |
| Method | blob |
The number of the blob within the specified cluster where the content of this entry is stored. |
| Method | cluster |
The number of the cluster the content of this entry is stored in |
| Method | get |
Get the cluster containing the blob containing the content of this entry. |
| Method | get |
Calculate the size of this object when written to a file. |
| Method | get |
Return the (decompressed) size of the content of this entry. |
| Method | iter |
Read the content of this entry iteratively. |
| Method | read |
Read the content of this entry. |
| Method | set |
Set the content of this entry. |
| Method | to |
Serialize this entry into a bytestring and return it. |
| Constant | FORMAT |
the format of this entry, excluding the mimetype |
| Constant | LENGTH |
Undocumented |
| Class Variable | LENGTH |
length of this entry, excluding mimetype and zero terminated parts |
| Property | blob |
The number of the blob within the specified cluster where the content of this entry is stored. |
| Property | cluster |
The number of the cluster the content of this entry is stored in. |
| Instance Variable | _blob |
number of the blob within the specified cluster where the content of this entry is stored |
| Instance Variable | _cluster |
number of the cluster the content of this entry is stored in |
Inherited from BaseEntry:
| 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 | flush |
Write this entry to the archive if it is dirty. |
| Method | full |
The full URL, composed of namespace and url. |
| Method | is |
Whether this entry is an article or not. |
| Method | mimetype |
The mimetype as a string. Only available when bound. |
| Method | mimetype |
The index of the mimetype in the mimetypelist. |
| Method | namespace |
The namespace this entry is part of. |
| Method | parameters |
The extra parameters of this entry. |
| Method | remove |
Remove this entry from the archive it is bound to. |
| Method | resolve |
If this entry is a redirect, follow this redirect and any subsequent redirects until a non-redirect is reached and return it. Otherwise, return this entry. |
| Method | revision |
The revision of the content of this entry. Unused, must be 0.. |
| Method | title |
The title of this entry. |
| Method | url |
The URL of this entry. |
| Constant | FORMAT |
the struct format to parse the mimetype |
| Constant | LENGTH |
length of the mimetype part of the struct |
| Constant | MIMETYPE |
mimetype index that identifies redirects |
| Instance Variable | mimetype |
The index of the mimetype in the mimetypelist. |
| Instance Variable | namespace |
The namespace this entry is part of. |
| Instance Variable | url |
The URL of this entry. |
| Property | full |
The full URL, composed of namespace and url. |
| Property | is |
Whether this entry is an article or not. |
| Property | is |
True if this entry is a redirect, False otherwise. |
| Property | mimetype |
The mimetype as string. Only available when bound. |
| Property | parameters |
The extra parameters of this entry. |
| Property | revision |
The revision of the content of this entry. Unused, must be 0. |
| Property | title |
The title of this entry. |
| Property | unmodified |
The full URL of this entry of the time this entry was last read or flushed. |
| Method | _get |
Return the size of the mimetype on disk in bytes. |
| Instance Variable | _force |
force-set the article state of this entry |
| Instance Variable | _mimetype |
index of mimetype in the mimetypelist. |
| Instance Variable | _namespace |
namespace this entry is part of |
| Instance Variable | _old |
full URL of entry as of last read/flush |
| Instance Variable | _parameters |
extra parameters. Unused, must be None. |
| Instance Variable | _revision |
the revision of the content of this entry. Unused, must be 0. |
| Instance Variable | _title |
title of this entry |
| Instance Variable | _url |
url of this entry |
Inherited from BindableMixIn (via BaseEntry):
| Method | bind |
Bind this object to a ZIM file. |
| Method | unbind |
Unbind this object. Can be called multiple times. |
| Property | bound |
Whether this object is bound to a ZIM file or not. |
| Property | zim |
The bound ZIM archive, if any is bound. Otherwise None. |
| Instance Variable | _zim |
the bound ZIM archive or None |
Inherited from ModifiableMixIn (via BaseEntry, BindableMixIn):
| Method | add |
Add another modifiable object as a child of this one. |
| 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. |
pyzim.entry.BaseEntry.from_fileRead a content entry from a file.
| Parameters | |
| f:file-like | file-like object to read from |
mimetype:int | index of mimetype. If specified, do not read it from file |
seek:int or None | if specified, seek this position of the file before reading |
| Returns | |
pyzim.entry.ContentEntry | the entry read from the file |
pyzim.entry.BaseEntry.__init__The default constructor.
| Parameters | |
mimetype:int | index of mimetype in the mimetypelist. |
namespace:str | namespace this entry is part of |
revision:int | the revision of the content of this entry. Unused, must be 0. |
clusterint | number of the cluster the content of this entry is stored in |
blobint | number of the blob within the specified cluster where the content of this entry is stored |
url:str | url of this entry |
title:str | title of this entry |
parameters:list | extra parameters. Unused, must be empty. |
The number of the blob within the specified cluster where the content of this entry is stored.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The number of the cluster the content of this entry is stored in
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
Get the cluster containing the blob containing the content of this entry.
| Returns | |
pyzim.cluster.Cluster | the cluster, which contains the blob that contains the content of this entry |
| Raises | |
pyzim.exceptions.BindRequired | when not bound |
pyzim.entry.BaseEntry.get_disk_sizeCalculate 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 |
Return the (decompressed) size of the content of this entry.
| Returns | |
int | the size of the content of this entry |
| Raises | |
pyzim.exceptions.BindRequired | when not bound |
Read the content of this entry iteratively.
The parameters 'start' and 'end' can be used to specify a range within the content of the entry to read. In this case, both values are interpreted relative to the actual blob start. Similar to how python slices work, the 'start' value will be inclusive and the 'end' value exclusive. If start >= size of the blob, the return value will be b"". If the end lies outside the blob, read only up until the end of the blob.
| Parameters | |
buffersize:int | number of bytes to read at once |
| start | Undocumented |
| end | Undocumented |
| Yields | |
bytes | chunks of the content of this entry in sequential order |
| Raises | |
pyzim.exceptions.BindRequired | when not bound |
TypeError | on invalid parameter type |
ValueError | on invalid parameter value |
Read the content of this entry.
The parameters 'start' and 'end' can be used to specify a range within the content of the entry to read. In this case, both values are interpreted relative to the actual blob start. Similar to how python slices work, the 'start' value will be inclusive and the 'end' value exclusive. If start >= size of the blob, the return value will be b"". If the end lies outside the blob, read only up until the end of the blob.
| Parameters | |
start:None or int | if specified, the offset relative to the start of the blob to start reading from |
end:None or int | if specified, the offset relative to the start of the blob to stop reading at |
| Returns | |
bytes | the content of this entry |
| Raises | |
pyzim.exceptions.BindRequired | when not bound |
TypeError | on invalid parameter type |
ValueError | on invalid parameter value |
Set the content of this entry.
This method does not flush the modified cluster, but it does return the cluster, so you can just call .flush() on this.
| Parameters | |
blobpyzim.blob.BaseBlobSource or str or bytes | blob source or str/bytes to use as content |
| Returns | |
pyzim.cluster.ModifiableClusterWrapper | the cluster this blob is part of |
| Raises | |
TypeError | on invalid type |
pyzim.exceptions.BindRequired | when not bound |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
pyzim.entry.BaseEntry.to_bytesSerialize this entry into a bytestring and return it.
| Returns | |
bytes | a bytestring representing the content of this entry. |