Skip to content

Commit

Permalink
Remove deprecated blosc code
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Mar 1, 2025
1 parent a2bdbe5 commit 6fe7b3e
Showing 1 changed file with 0 additions and 171 deletions.
171 changes: 0 additions & 171 deletions numcodecs/blosc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ cdef extern from "blosc.h":
void* src, void* dest, size_t destsize) nogil
int blosc_decompress(void *src, void *dest, size_t destsize) nogil
int blosc_getitem(void* src, int start, int nitems, void* dest)
int blosc_compname_to_compcode(const char* compname)
int blosc_compress_ctx(int clevel, int doshuffle, size_t typesize, size_t nbytes,
const void* src, void* dest, size_t destsize,
const char* compressor, size_t blocksize,
Expand Down Expand Up @@ -100,27 +99,6 @@ def _init():
"""Initialize the Blosc library environment."""
blosc_init()

init = deprecated(_init)


def _destroy():
"""Destroy the Blosc library environment."""
blosc_destroy()


destroy = deprecated(_destroy)


def _compname_to_compcode(cname):
"""Return the compressor code associated with the compressor name. If the compressor
name is not recognized, or there is not support for it in this build, -1 is returned
instead."""
if isinstance(cname, str):
cname = cname.encode('ascii')
return blosc_compname_to_compcode(cname)

compname_to_compcode = deprecated(_compname_to_compcode)


def list_compressors():
"""Get a list of compressors supported in the current build."""
Expand All @@ -141,35 +119,6 @@ def set_nthreads(int nthreads):
return blosc_set_nthreads(nthreads)


def _cbuffer_sizes(source):
"""Return information about a compressed buffer, namely the number of uncompressed
bytes (`nbytes`) and compressed (`cbytes`). It also returns the `blocksize` (which
is used internally for doing the compression by blocks).
Returns
-------
nbytes : int
cbytes : int
blocksize : int
"""
cdef:
Buffer buffer
size_t nbytes, cbytes, blocksize

# obtain buffer
buffer = Buffer(source, PyBUF_ANY_CONTIGUOUS)

# determine buffer size
blosc_cbuffer_sizes(buffer.ptr, &nbytes, &cbytes, &blocksize)

# release buffers
buffer.release()

return nbytes, cbytes, blocksize

cbuffer_sizes = deprecated(_cbuffer_sizes)

def cbuffer_complib(source):
"""Return the name of the compression library used to compress `source`."""
cdef:
Expand All @@ -189,45 +138,6 @@ def cbuffer_complib(source):
return complib


def _cbuffer_metainfo(source):
"""Return some meta-information about the compressed buffer in `source`, including
the typesize, whether the shuffle or bit-shuffle filters were used, and the
whether the buffer was memcpyed.
Returns
-------
typesize
shuffle
memcpyed
"""
cdef:
Buffer buffer
size_t typesize
int flags

# obtain buffer
buffer = Buffer(source, PyBUF_ANY_CONTIGUOUS)

# determine buffer size
blosc_cbuffer_metainfo(buffer.ptr, &typesize, &flags)

# release buffers
buffer.release()

# decompose flags
if flags & BLOSC_DOSHUFFLE:
shuffle = SHUFFLE
elif flags & BLOSC_DOBITSHUFFLE:
shuffle = BITSHUFFLE
else:
shuffle = NOSHUFFLE
memcpyed = flags & BLOSC_MEMCPYED

return typesize, shuffle, memcpyed

cbuffer_metainfo = deprecated(_cbuffer_metainfo)

def _err_bad_cname(cname):
raise ValueError('bad compressor or compressor not supported: %r; expected one of '
'%s' % (cname, list_compressors()))
Expand Down Expand Up @@ -415,82 +325,6 @@ def decompress(source, dest=None):

return dest


def _decompress_partial(source, start, nitems, dest=None):
"""**Experimental**
Decompress data of only a part of a buffer.
Parameters
----------
source : bytes-like
Compressed data, including blosc header. Can be any object supporting the buffer
protocol.
start: int,
Offset in item where we want to start decoding
nitems: int
Number of items we want to decode
dest : array-like, optional
Object to decompress into.
Returns
-------
dest : bytes
Object containing decompressed data.
"""
cdef:
int ret
int encoding_size
int nitems_bytes
int start_bytes
char *source_ptr
char *dest_ptr
Buffer source_buffer
Buffer dest_buffer = None

# setup source buffer
source_buffer = Buffer(source, PyBUF_ANY_CONTIGUOUS)
source_ptr = source_buffer.ptr

# get encoding size from source buffer header
encoding_size = source[3]

# convert variables to handle type and encoding sizes
nitems_bytes = nitems * encoding_size
start_bytes = (start * encoding_size)

# setup destination buffer
if dest is None:
dest = PyBytes_FromStringAndSize(NULL, nitems_bytes)
dest_ptr = PyBytes_AS_STRING(dest)
dest_nbytes = nitems_bytes
else:
arr = ensure_contiguous_ndarray(dest)
dest_buffer = Buffer(arr, PyBUF_ANY_CONTIGUOUS | PyBUF_WRITEABLE)
dest_ptr = dest_buffer.ptr
dest_nbytes = dest_buffer.nbytes

# try decompression
try:
if dest_nbytes < nitems_bytes:
raise ValueError('destination buffer too small; expected at least %s, '
'got %s' % (nitems_bytes, dest_nbytes))
ret = blosc_getitem(source_ptr, start, nitems, dest_ptr)

finally:
source_buffer.release()
if dest_buffer is not None:
dest_buffer.release()

# ret refers to the number of bytes returned from blosc_getitem.
if ret <= 0:
raise RuntimeError('error during blosc partial decompression: %d', ret)

return dest

decompress_partial = deprecated(_decompress_partial)

# set the value of this variable to True or False to override the
# default adaptive behaviour
use_threads = None
Expand Down Expand Up @@ -584,11 +418,6 @@ class Blosc(Codec):
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
return decompress(buf, out)

def decode_partial(self, buf, int start, int nitems, out=None):
'''**Experimental**'''
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
return _decompress_partial(buf, start, nitems, dest=out)

def __repr__(self):
r = '%s(cname=%r, clevel=%r, shuffle=%s, blocksize=%s)' % \
(type(self).__name__,
Expand Down

0 comments on commit 6fe7b3e

Please sign in to comment.