DeflateCompressor ================= .. cpp:class:: numpy::DeflateCompressor numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use DeflateCompressor DeflateCompressor obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static std::vector compress(const void\* data, size_t size, int level = 6)`` - static std::vector - np_npz_utils.h:148 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static std::vector decompress(const void\* data, size_t compressed_size, size_t uncompressed_size)`` - static std::vector - np_npz_utils.h:176 - * - ``deflateEnd(&zs)`` - - np_npz_utils.h:166 - * - ``inflateEnd(&zs)`` - - np_npz_utils.h:191 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-deflatecompressor-compress-0: .. dropdown:: compress (np_test_5_all.cpp:71) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 61 :emphasize-lines: 11 void np_test_zlib_basic_compression() { std::cout << "========= basic compression/decompression ======================="; const char* original = "Hello, zlib! This is a test string for compression."; size_t original_len = std::strlen(original) + 1; // Compress uLongf compressed_len = compressBound(static_cast(original_len)); std::vector compressed(compressed_len); int result = compress(compressed.data(), &compressed_len, (const Bytef*)original, static_cast(original_len)); if (result != Z_OK) { std::cout << " [FAIL] : in np_test_zlib_basic_compression() : Compression failed"; throw std::runtime_error("np_test_zlib_basic_compression failed: Compression failed"); } // Decompress uLongf decompressed_len = static_cast(original_len); std::vector decompressed(decompressed_len);