class documentation

A compression strategy that compresses into a single cluster.

New clusters are created if the current cluster's uncompressed size would exceed SimpleCompressionStrategy.max_size.

Method __init__ The default constructor.
Method add_item Handle the addition of an item (e.g. create entries, ...).
Method flush Flush all current items.
Method has_items True if this compression strategy still has items to be written.
Instance Variable cluster current cluster
Instance Variable compression_type compression type to use
Instance Variable entries list of entries to compress
Instance Variable max_size max (uncompressed) size the cluster should have. This may be exceeded.
Method _finalize_current_cluster Finalize the current cluster, writing it and the various items.
Method _new_cluster Instantiate a new cluster.
Method _new_cluster_needed Check if a new cluster is needed for the item.
Instance Variable _lock thread safety lock

Inherited from BaseCompressionStrategy:

Instance Variable zim zim archive this compression strategy compresses for
def __init__(self, zim, compression_type, max_size=2 * 1024 * 1024):

The default constructor.

Parameters
zim:pyzim.archive.Zimzim archive this compression strategy compresses for
compression_type:pyzim.compression.CompressionTypecompression type to use
max_size:intmax (uncompressed) size the cluster should have. This may be exceeded.
def add_item(self, item):

Handle the addition of an item (e.g. create entries, ...).

Parameters
item:pyzim.item.Itemitem to add
def flush(self):

Flush all current items.

This should create and flush all remaining clusters and entries.

def has_items(self):

True if this compression strategy still has items to be written.

Returns
boolwhether there are some items that still need to be written

compression type to use

list of entries to compress

max_size: int =

max (uncompressed) size the cluster should have. This may be exceeded.

def _finalize_current_cluster(self):

Finalize the current cluster, writing it and the various items.

def _new_cluster(self):

Instantiate a new cluster.

The new cluster is in SimpleCompressionStrategy.cluster. This method does not take care of flushing the previous cluster.

def _new_cluster_needed(self, item):

Check if a new cluster is needed for the item.

Parameters
item:pyzim.item.Itemitem to check
Returns
boolTrue if the current cluster should be finalized.

thread safety lock