示例#1
0
def compress(bytesobj, typesize=8, clevel=9, shuffle=blosc.SHUFFLE,
             cname='blosclz'):
    """compress(bytesobj[, typesize=8, clevel=9, shuffle=blosc.SHUFFLE, cname='blosclz']])

    Compress bytesobj, with a given type size.

    Parameters
    ----------
    bytesobj : bytes-like object (supporting the buffer interface)
        The data to be compressed.
    typesize : int
        The data type size.
    clevel : int (optional)
        The compression level from 0 (no compression) to 9
        (maximum compression).  The default is 9.
    shuffle : int (optional)
        The shuffle filter to be activated.  Allowed values are
        blosc.NOSHUFFLE, blosc.SHUFFLE and blosc.BITSHUFFLE.  The
        default is blosc.SHUFFLE.
    cname : string (optional)
        The name of the compressor used internally in Blosc.
        It can be any of the supported by Blosc ('blosclz',
        'lz4', 'lz4hc', 'snappy', 'zlib' and maybe others too).
        The default is 'blosclz'.

    Returns
    -------
    out : str / bytes
        The compressed data in form of a Python str / bytes object.

    Raises
    ------
    TypeError
        If bytesobj doesn't support the buffer interface.
    ValueError
        If bytesobj is too long.
        If typesize is not within the allowed range.
        If clevel is not within the allowed range.
        If cname is not a valid codec.

    Examples
    --------

    >>> import array
    >>> a = array.array('i', range(1000*1000))
    >>> a_bytesobj = a.tostring()
    >>> c_bytesobj = blosc.compress(a_bytesobj, typesize=4)
    >>> len(c_bytesobj) < len(a_bytesobj)
    True

    """

    _check_input_length('bytesobj', len(bytesobj))
    _check_typesize(typesize)
    _check_shuffle(shuffle)
    _check_clevel(clevel)
    _check_cname(cname)

    return _ext.compress(bytesobj, typesize, clevel, shuffle, cname)
示例#2
0
def compress(bytesobj, typesize=8, clevel=9, shuffle=blosc.SHUFFLE,
             cname='blosclz'):
    """compress(bytesobj[, typesize=8, clevel=9, shuffle=blosc.SHUFFLE, cname='blosclz']])

    Compress bytesobj, with a given type size.

    Parameters
    ----------
    bytesobj : bytes-like object (supporting the buffer interface)
        The data to be compressed.
    typesize : int
        The data type size.
    clevel : int (optional)
        The compression level from 0 (no compression) to 9
        (maximum compression).  The default is 9.
    shuffle : int (optional)
        The shuffle filter to be activated.  Allowed values are
        blosc.NOSHUFFLE, blosc.SHUFFLE and blosc.BITSHUFFLE.  The
        default is blosc.SHUFFLE.
    cname : string (optional)
        The name of the compressor used internally in Blosc. It can be
        any of the supported by Blosc ('blosclz', 'lz4', 'lz4hc',
        'snappy', 'zlib', 'zstd' and maybe others too). The default is
        'blosclz'.

    Returns
    -------
    out : str / bytes
        The compressed data in form of a Python str / bytes object.

    Raises
    ------
    TypeError
        If bytesobj doesn't support the buffer interface.
    ValueError
        If bytesobj is too long.
        If typesize is not within the allowed range.
        If clevel is not within the allowed range.
        If cname is not a valid codec.

    Examples
    --------

    >>> import array
    >>> a = array.array('i', range(1000*1000))
    >>> a_bytesobj = a.tostring()
    >>> c_bytesobj = blosc.compress(a_bytesobj, typesize=4)
    >>> len(c_bytesobj) < len(a_bytesobj)
    True

    """

    _check_input_length('bytesobj', len(bytesobj))
    _check_typesize(typesize)
    _check_shuffle(shuffle)
    _check_clevel(clevel)
    _check_cname(cname)

    return _ext.compress(bytesobj, typesize, clevel, shuffle, cname)
示例#3
0
def compress(bytesobj, typesize, clevel=9, shuffle=True, cname='blosclz'):
    """compress(bytesobj, typesize[, clevel=9, shuffle=True, cname='blosclz']])

    Compress bytesobj, with a given type size.

    Parameters
    ----------
    bytesobj : str / bytes
        The data to be compressed.
    typesize : int
        The data type size.
    clevel : int (optional)
        The compression level from 0 (no compression) to 9
        (maximum compression).  The default is 9.
    shuffle : bool (optional)
        Whether you want to activate the shuffle filter or not.
        The default is True.
    cname : string (optional)
        The name of the compressor used internally in Blosc.
        It can be any of the supported by Blosc ('blosclz',
        'lz4', 'lz4hc', 'snappy', 'zlib' and maybe others too).
        The default is 'blosclz'.

    Returns
    -------
    out : str / bytes
        The compressed data in form of a Python str / bytes object.

    Raises
    ------
    TypeError
        If bytesobj is not of type bytes or string.
    ValueError
        If bytesobj is too long.
        If typesize is not within the allowed range.
        if clevel is not not within the allowed range.

    Examples
    --------

    >>> import array
    >>> a = array.array('i', range(1000*1000))
    >>> a_bytesobj = a.tostring()
    >>> c_bytesobj = blosc.compress(a_bytesobj, typesize=4)
    >>> len(c_bytesobj) < len(a_bytesobj)
    True

    """

    _check_bytesobj(bytesobj)
    _check_input_length('bytesobj', len(bytesobj))
    _check_typesize(typesize)
    _check_clevel(clevel)
    _check_cname(cname)

    return _ext.compress(bytesobj, typesize, clevel, shuffle, cname)
示例#4
0
def compress(bytesobj, typesize, clevel=9, shuffle=True, cname='blosclz'):
    """compress(bytesobj, typesize[, clevel=9, shuffle=True, cname='blosclz']])

    Compress bytesobj, with a given type size.

    Parameters
    ----------
    bytesobj : str / bytes
        The data to be compressed.
    typesize : int
        The data type size.
    clevel : int (optional)
        The compression level from 0 (no compression) to 9
        (maximum compression).  The default is 9.
    shuffle : bool (optional)
        Whether you want to activate the shuffle filter or not.
        The default is True.
    cname : string (optional)
        The name of the compressor used internally in Blosc.
        It can be any of the supported by Blosc ('blosclz',
        'lz4', 'lz4hc', 'snappy', 'zlib' and maybe others too).
        The default is 'blosclz'.

    Returns
    -------
    out : str / bytes
        The compressed data in form of a Python str / bytes object.

    Raises
    ------
    TypeError
        If bytesobj is not of type bytes or string.
    ValueError
        If bytesobj is too long.
        If typesize is not within the allowed range.
        if clevel is not not within the allowed range.

    Examples
    --------

    >>> import array
    >>> a = array.array('i', range(1000*1000))
    >>> a_bytesobj = a.tostring()
    >>> c_bytesobj = blosc.compress(a_bytesobj, typesize=4)
    >>> len(c_bytesobj) < len(a_bytesobj)
    True

    """

    _check_bytesobj(bytesobj)
    _check_input_length('bytesobj', len(bytesobj))
    _check_typesize(typesize)
    _check_clevel(clevel)
    _check_cname(cname)

    return _ext.compress(bytesobj, typesize, clevel, shuffle, cname)
示例#5
0
def compress(bytesobj, typesize, clevel=9, shuffle=True):
    """compress(bytesobj, typesize[, clevel=9, shuffle=True]])

    Compress bytesobj, with a given type size.

    Parameters
    ----------
        bytesobj : str / bytes
            The data to be compressed.
        typesize : int
            The data type size.
        clevel : int (optional)
            The compression level from 0 (no compression) to 9
            (maximum compression).  The default is 9.
        shuffle : bool (optional)
            Whether you want to activate the shuffle filter or not.
            The default is True.

    Returns
    -------
        out : str / bytes
            The compressed data in form of a Python str / bytes object.

    Examples
    --------

    >>> import array
    >>> a = array.array('i', range(1000*1000))
    >>> a_bytesobj = a.tostring()
    >>> c_bytesobj = compress(a_bytesobj, typesize=4)
    >>> len(c_bytesobj) < len(a_bytesobj)
    True

    """

    if type(bytesobj) is not bytes:
        raise ValueError(
            "only string (2.x) or bytes (3.x) objects supported as input")

    if len(bytesobj) > _ext.BLOSC_MAX_BUFFERSIZE:
        raise ValueError("bytesobj length cannot be larger than %d bytes" % \
                         _ext.BLOSC_MAX_BUFFERSIZE)

    if clevel < 0 or clevel > 9:
        raise ValueError("clevel can only be in the 0-9 range.")

    return _ext.compress(bytesobj, typesize, clevel, shuffle)