コード例 #1
0
static PyObject *
PyBlosc_compress(PyObject *self, PyObject *args)
{
  Py_buffer view;
  PyObject *output;
  void *input;
  size_t nbytes, typesize;
  int clevel, shuffle;
  char *cname;
  const char *format;

  /* Accept some kind of input followed by
   * typesize, clevel, shuffle and cname */
#if PY_MAJOR_VERSION <= 2
  /* s* : bytes like object including unicode and anything that supports
   * the buffer interface */
  format = "s*niis:compress";
#elif PY_MAJOR_VERSION >= 3
  /* y* :bytes like object EXCLUDING unicode and anything that supports
   * the buffer interface. This is the recommended way to accept binary
   * data in Python 3. */
  format = "y*niis:compress";
#endif
  if (!PyArg_ParseTuple(args, format , &view,
                        &typesize, &clevel, &shuffle, &cname))
    return NULL;
  nbytes = view.len;
  input = view.buf;
  output = compress_helper(input, nbytes, typesize, clevel, shuffle, cname);
  PyBuffer_Release(&view);
  return output;
}
コード例 #2
0
ファイル: blosc_extension.c プロジェクト: B-Rich/python-blosc
static PyObject *
PyBlosc_compress(PyObject *self, PyObject *args)
{
    void *input;
    size_t nbytes, typesize;
    int clevel, shuffle;
    char *cname;

    /* require Python string object, typesize, clevel and shuffle agrs */
    if (!PyArg_ParseTuple(args, "s#niis:compress", &input, &nbytes,
                          &typesize, &clevel, &shuffle, &cname))
      return NULL;
    return compress_helper(input, nbytes, typesize, clevel, shuffle, cname);
}
コード例 #3
0
ファイル: blosc_extension.c プロジェクト: B-Rich/python-blosc
static PyObject *
PyBlosc_compress_ptr(PyObject *self, PyObject *args)
{
    PyObject * input;
    void * input_ptr;
    size_t nbytes, typesize;
    int clevel, shuffle;
    char *cname;

    /* require an address, buffer length, typesize, clevel, shuffle and cname */
    if (!PyArg_ParseTuple(args, "Onniis:compress", &input, &nbytes,
                          &typesize, &clevel, &shuffle, &cname))
      return NULL;
    /*  convert to void pointer safely */
    input_ptr = PyLong_AsVoidPtr(input);
    if (input_ptr == NULL)
      return NULL;
    return compress_helper(input_ptr, nbytes, typesize, clevel, shuffle, cname);
}