OpenQuizz
Une application de gestion des contenus pédagogiques
PackEntity Class Reference
Inheritance diagram for PackEntity:
Collaboration diagram for PackEntity:

Public Member Functions

def __init__ (self, pack_or_index_path)
 
def close (self)
 
def info (self, sha)
 
def stream (self, sha)
 
def info_at_index (self, index)
 
def stream_at_index (self, index)
 
def pack (self)
 
def index (self)
 
def is_valid_stream (self, sha, use_crc=False)
 
def info_iter (self)
 
def stream_iter (self)
 
def collect_streams_at_offset (self, offset)
 
def collect_streams (self, sha)
 
def write_pack (cls, object_iter, pack_write, index_write=None, object_count=None, zlib_compression=zlib.Z_BEST_SPEED)
 
def create (cls, object_iter, base_dir, object_count=None, zlib_compression=zlib.Z_BEST_SPEED)
 
- Public Member Functions inherited from LazyMixin
def __getattr__ (self, attr)
 

Static Public Attributes

 IndexFileCls
 
 PackFileCls
 

Detailed Description

Combines the PackIndexFile and the PackFile into one, allowing the
actual objects to be resolved and iterated

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  pack_or_index_path 
)
Initialize ourselves with the path to the respective pack or index file

Member Function Documentation

◆ close()

def close (   self)

◆ collect_streams()

def collect_streams (   self,
  sha 
)
As ``PackFile.collect_streams``, but takes a sha instead of an offset.
Additionally, ref_delta streams will be resolved within this pack.
If this is not possible, the stream will be left alone, hence it is adivsed
to check for unresolved ref-deltas and resolve them before attempting to
construct a delta stream.

:param sha: 20 byte sha1 specifying the object whose related streams you want to collect
:return: list of streams, first being the actual object delta, the last being
    a possibly unresolved base object.
:raise BadObject:

◆ collect_streams_at_offset()

def collect_streams_at_offset (   self,
  offset 
)
As the version in the PackFile, but can resolve REF deltas within this pack
For more info, see ``collect_streams``

:param offset: offset into the pack file at which the object can be found

◆ create()

def create (   cls,
  object_iter,
  base_dir,
  object_count = None,
  zlib_compression = zlib.Z_BEST_SPEED 
)
Create a new on-disk entity comprised of a properly named pack file and a properly named
and corresponding index file. The pack contains all OStream objects contained in object iter.
:param base_dir: directory which is to contain the files
:return: PackEntity instance initialized with the new pack

**Note:** for more information on the other parameters see the write_pack method

◆ index()

def index (   self)
:return: the underlying pack index file instance

◆ info()

def info (   self,
  sha 
)
Retrieve information about the object identified by the given sha

:param sha: 20 byte sha1
:raise BadObject:
:return: OInfo instance, with 20 byte sha

◆ info_at_index()

def info_at_index (   self,
  index 
)
As ``info``, but uses a PackIndexFile compatible index to refer to the object

◆ info_iter()

def info_iter (   self)
:return: Iterator over all objects in this pack. The iterator yields
    OInfo instances

◆ is_valid_stream()

def is_valid_stream (   self,
  sha,
  use_crc = False 
)
Verify that the stream at the given sha is valid.

:param use_crc: if True, the index' crc is run over the compressed stream of
    the object, which is much faster than checking the sha1. It is also
    more prone to unnoticed corruption or manipulation.
:param sha: 20 byte sha1 of the object whose stream to verify
    whether the compressed stream of the object is valid. If it is
    a delta, this only verifies that the delta's data is valid, not the
    data of the actual undeltified object, as it depends on more than
    just this stream.
    If False, the object will be decompressed and the sha generated. It must
    match the given sha

:return: True if the stream is valid
:raise UnsupportedOperation: If the index is version 1 only
:raise BadObject: sha was not found

◆ pack()

def pack (   self)
:return: the underlying pack file instance

◆ stream()

def stream (   self,
  sha 
)
Retrieve an object stream along with its information as identified by the given sha

:param sha: 20 byte sha1
:raise BadObject:
:return: OStream instance, with 20 byte sha

◆ stream_at_index()

def stream_at_index (   self,
  index 
)
As ``stream``, but uses a PackIndexFile compatible index to refer to the
object

◆ stream_iter()

def stream_iter (   self)
:return: iterator over all objects in this pack. The iterator yields
    OStream instances

◆ write_pack()

def write_pack (   cls,
  object_iter,
  pack_write,
  index_write = None,
  object_count = None,
  zlib_compression = zlib.Z_BEST_SPEED 
)
Create a new pack by putting all objects obtained by the object_iterator
into a pack which is written using the pack_write method.
The respective index is produced as well if index_write is not Non.

:param object_iter: iterator yielding odb output objects
:param pack_write: function to receive strings to write into the pack stream
:param indx_write: if not None, the function writes the index file corresponding
    to the pack.
:param object_count: if you can provide the amount of objects in your iteration,
    this would be the place to put it. Otherwise we have to pre-iterate and store
    all items into a list to get the number, which uses more memory than necessary.
:param zlib_compression: the zlib compression level to use
:return: tuple(pack_sha, index_binsha) binary sha over all the contents of the pack
    and over all contents of the index. If index_write was None, index_binsha will be None

**Note:** The destination of the write functions is up to the user. It could
be a socket, or a file for instance

**Note:** writes only undeltified objects

Field Documentation

◆ IndexFileCls

IndexFileCls
static

◆ PackFileCls

PackFileCls
static

The documentation for this class was generated from the following file: