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

Public Member Functions

def __init__ (self, m, close_on_deletion, size=None)
 
def __del__ (self)
 
def new (self, m, close_on_deletion=False)
 
def data (self)
 
def close (self)
 
def compressed_bytes_read (self)
 
def seek (self, offset, whence=getattr(os, 'SEEK_SET', 0))
 
def read (self, size=-1)
 
- Public Member Functions inherited from LazyMixin
def __getattr__ (self, attr)
 

Static Public Attributes

 max_read_size
 

Detailed Description

Reads data in chunks from a memory map and decompresses it. The client sees
only the uncompressed data, respective file-like read calls are handling on-demand
buffered decompression accordingly

A constraint on the total size of bytes is activated, simulating
a logical file within a possibly larger physical memory area

To read efficiently, you clearly don't want to read individual bytes, instead,
read a few kilobytes at least.

**Note:** The chunk-size should be carefully selected as it will involve quite a bit
    of string copying due to the way the zlib is implemented. Its very wasteful,
    hence we try to find a good tradeoff between allocation time and number of
    times we actually allocate. An own zlib implementation would be good here
    to better support streamed reading - it would only need to keep the mmap
    and decompress it into chunks, that's all ... 

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  m,
  close_on_deletion,
  size = None 
)
Initialize with mmap for stream reading
:param m: must be content data - use new if you have object data and no size

◆ __del__()

def __del__ (   self)

Member Function Documentation

◆ close()

def close (   self)
Close our underlying stream of compressed bytes if this was allowed during initialization
:return: True if we closed the underlying stream
:note: can be called safely 

◆ compressed_bytes_read()

def compressed_bytes_read (   self)
:return: number of compressed bytes read. This includes the bytes it
    took to decompress the header ( if there was one )

◆ data()

def data (   self)
:return: random access compatible data we are working on

◆ new()

def new (   self,
  m,
  close_on_deletion = False 
)
Create a new DecompressMemMapReader instance for acting as a read-only stream
This method parses the object header from m and returns the parsed
type and size, as well as the created stream instance.

:param m: memory map on which to operate. It must be object data ( header + contents )
:param close_on_deletion: if True, the memory map will be closed once we are
    being deleted

◆ read()

def read (   self,
  size = -1 
)

◆ seek()

def seek (   self,
  offset,
  whence = getattr(os, 'SEEK_SET', 0) 
)
Allows to reset the stream to restart reading
:raise ValueError: If offset and whence are not 0

Field Documentation

◆ max_read_size

max_read_size
static

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