@@ -8,14 +8,12 @@ import threading
88import os
99
1010
11- # noinspection PyUnresolvedReferences
12- from cpython cimport array, PyObject
13- import array
14- from cpython.buffer cimport PyObject_GetBuffer, PyBuffer_Release, PyBUF_ANY_CONTIGUOUS, \
15- PyBUF_WRITEABLE
11+ from cpython.buffer cimport PyBUF_ANY_CONTIGUOUS, PyBUF_WRITEABLE
1612from cpython.bytes cimport PyBytes_FromStringAndSize, PyBytes_AS_STRING
1713
1814
15+ from numcodecs.compat_ext cimport MyBuffer
16+ from numcodecs.compat_ext import MyBuffer
1917from numcodecs.compat import PY2, text_type
2018from numcodecs.abc import Codec
2119
@@ -98,37 +96,6 @@ def set_nthreads(int nthreads):
9896 return blosc_set_nthreads(nthreads)
9997
10098
101- cdef class MyBuffer:
102- """ Compatibility class to work around fact that array.array does not support new-style buffer
103- interface in PY2."""
104-
105- cdef:
106- char * ptr
107- Py_buffer buffer
108- size_t nbytes
109- size_t itemsize
110- array.array arr
111- bint new_buffer
112-
113- def __cinit__ (self , obj , flags ):
114- if PY2 and isinstance (obj, array.array):
115- self .new_buffer = False
116- self .arr = obj
117- self .ptr = < char * > self .arr.data.as_voidptr
118- self .itemsize = self .arr.itemsize
119- self .nbytes = self .arr.buffer_info()[1 ] * self .itemsize
120- else :
121- self .new_buffer = True
122- PyObject_GetBuffer(obj, & (self .buffer), flags)
123- self .ptr = < char * > self .buffer.buf
124- self .itemsize = self .buffer.itemsize
125- self .nbytes = self .buffer.len
126-
127- def release (self ):
128- if self .new_buffer:
129- PyBuffer_Release(& (self .buffer))
130-
131-
13299def cbuffer_sizes (source ):
133100 """ Return information about a compressed buffer, namely the number of uncompressed bytes (
134101 `nbytes`) and compressed (`cbytes`). It also returns the `blocksize` (which is used
@@ -358,6 +325,10 @@ class Blosc(Codec):
358325 The requested size of the compressed blocks. If 0 (default), an automatic blocksize will
359326 be used.
360327
328+ See Also
329+ --------
330+ numcodecs.zstd.Zstd, numcodecs.lz4.LZ4
331+
361332 """
362333
363334 codec_id = ' blosc'
0 commit comments