in sparkey/__init__.py [0:0]
def __init__(self, filename, mode='NEW',
compression_type=Compression.NONE, compression_block_size=0):
"""Creates or appends a log file.
Types of keys and values can be strings or bytes.
For Python 2, this is the same thing.
For Python 3, strings will be encoded as UTF-8
This is not threadsafe, don't write to the same file from
multiple threads or processes.
@param filename: file to create or append to.
@param mode: one of two modes:
- NEW: creates the file regardless of whether it
already exists or not.
- APPEND: appends to the log if it exists, otherwise
raises an exception.
@param compression_type: one of two types:
- NONE: keys and values are written as is, and
each key-value pair is considered a block of its own.
- SNAPPY: compression is done on a block level of at most
compression_block_size uncompressed bytes.
Each block may contain multiple key/value pairs and it may split
keys or values over block borders.
@param compression_block_size: mandatory unless compression is
NONE. This indicates how large the maximum block may be.
To get good compression and performance, this should be a
fairly small multiple of expected key + value size.
"""
filename = _to_bytes(filename, "filename")
log = _ptr()
self._log = log
if mode == 'NEW':
_logwriter_create(_byref(log), filename,
compression_type,
compression_block_size)
elif mode == 'APPEND':
_logwriter_append(_byref(log), filename)
else:
raise SparkeyException("Invalid mode %s, expected 'NEW' or "
"'APPEND'" % (mode))