Compress-Stream-Zstd

 view release on metacpan or  search on metacpan

ext/zstd/build/single_file_libs/examples/emscripten.c  view on Meta::CPAN

static GLuint progId = 0;

/**
 * Vertex shader ID.
 */
static GLuint vertId = 0;

/**
 * Fragment shader ID.
 */
static GLuint fragId = 0;

//********************************* Uniforms *********************************/

/**
 * Quad rotation angle ID.
 */
static GLint uRotId = -1;

/**
 * Draw colour ID.

ext/zstd/build/single_file_libs/examples/emscripten.c  view on Meta::CPAN

static GLchar const vertShader2D[] =
#if GL_ES_VERSION_2_0
	"#version 100\n"
	"precision mediump float;\n"
#else
	"#version 120\n"
#endif
	"uniform   float uRot;"	// rotation
	"attribute vec2  aPos;"	// vertex position coords
	"attribute vec2  aUV0;"	// vertex texture UV0
	"varying   vec2  vUV0;"	// (passed to fragment shader)
	"void main() {"
	"	float cosA = cos(radians(uRot));"
	"	float sinA = sin(radians(uRot));"
	"	mat3 rot = mat3(cosA, -sinA, 0.0,"
	"					sinA,  cosA, 0.0,"
	"					0.0,   0.0,  1.0);"
	"	gl_Position = vec4(rot * vec3(aPos, 1.0), 1.0);"
	"	vUV0 = aUV0;"
	"}";

/**
 * Fragment shader for the above polys.
 */
static GLchar const fragShader2D[] =
#if GL_ES_VERSION_2_0
	"#version 100\n"
	"precision mediump float;\n"
#else
	"#version 120\n"
#endif
	"uniform sampler2D uTx0;"
	"varying vec2      vUV0;" // (passed from fragment shader)
	"void main() {"
	"	gl_FragColor = texture2D(uTx0, vUV0);"
	"}";

/**
 * Helper to compile a shader.
 * 
 * \param type shader type
 * \param text shader source
 * \return the shader ID (or zero if compilation failed)

ext/zstd/build/single_file_libs/examples/emscripten.c  view on Meta::CPAN

 * 
 * As a (naive) comparison, removing Zstd and building with "-Os -g0 s WASM=1
 * -lGL emscripten.c" results in a 15kB WebAssembly file; re-adding Zstd
 * increases the Wasm by 26kB.
 */
int main() {
	if (initContext()) {
		// Compile shaders and set the initial GL state
		if ((progId = glCreateProgram())) {
			 vertId = compileShader(GL_VERTEX_SHADER,   vertShader2D);
			 fragId = compileShader(GL_FRAGMENT_SHADER, fragShader2D);
			 
			 glBindAttribLocation(progId, GL_VERT_POSXY_ID, "aPos");
			 glBindAttribLocation(progId, GL_VERT_TXUV0_ID, "aUV0");
			 
			 glAttachShader(progId, vertId);
			 glAttachShader(progId, fragId);
			 glLinkProgram (progId);
			 glUseProgram  (progId);
			 uRotId = glGetUniformLocation(progId, "uRot");
			 uTx0Id = glGetUniformLocation(progId, "uTx0");
			 if (uTx0Id >= 0) {
				 glUniform1i(uTx0Id, 0);
			 }
			
			 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			 glEnable(GL_BLEND);

ext/zstd/doc/zstd_manual.html  view on Meta::CPAN

</b></pre><BR>
<pre><b>size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); </b>/**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */...
</b></pre><BR>
<a name="Chapter22"></a><h2>Buffer-less streaming decompression (synchronous mode)</h2><pre>
  A ZSTD_DCtx object is required to track streaming operations.
  Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
  A ZSTD_DCtx object can be re-used multiple times.

  First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
  Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
  Data fragment must be large enough to ensure successful decoding.
 `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
  result  : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
           >0 : `srcSize` is too small, please provide at least result bytes on next attempt.
           errorCode, which can be tested using ZSTD_isError().

  It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
  such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
  Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
  As a consequence, check that values remain within valid application range.
  For example, do not allocate memory blindly, check that `windowSize` is within expectation.

ext/zstd/lib/compress/zstdmt_compress.c  view on Meta::CPAN

    for (u=0; u<bufPool->totalBuffers; u++)
        totalBufferSize += bufPool->bTable[u].capacity;
    ZSTD_pthread_mutex_unlock(&bufPool->poolMutex);

    return poolSize + totalBufferSize;
}

/* ZSTDMT_setBufferSize() :
 * all future buffers provided by this buffer pool will have _at least_ this size
 * note : it's better for all buffers to have same size,
 * as they become freely interchangeable, reducing malloc/free usages and memory fragmentation */
static void ZSTDMT_setBufferSize(ZSTDMT_bufferPool* const bufPool, size_t const bSize)
{
    ZSTD_pthread_mutex_lock(&bufPool->poolMutex);
    DEBUGLOG(4, "ZSTDMT_setBufferSize: bSize = %u", (U32)bSize);
    bufPool->bufferSize = bSize;
    ZSTD_pthread_mutex_unlock(&bufPool->poolMutex);
}


static ZSTDMT_bufferPool* ZSTDMT_expandBufferPool(ZSTDMT_bufferPool* srcBufPool, unsigned maxNbBuffers)

ext/zstd/lib/zstd.h  view on Meta::CPAN

size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize);   /* compression parameters are already set within cdict. pledgedSrcSize...
/**
  Buffer-less streaming decompression (synchronous mode)

  A ZSTD_DCtx object is required to track streaming operations.
  Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it.
  A ZSTD_DCtx object can be re-used multiple times.

  First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader().
  Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough.
  Data fragment must be large enough to ensure successful decoding.
 `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough.
  result  : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled.
           >0 : `srcSize` is too small, please provide at least result bytes on next attempt.
           errorCode, which can be tested using ZSTD_isError().

  It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
  such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
  Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
  As a consequence, check that values remain within valid application range.
  For example, do not allocate memory blindly, check that `windowSize` is within expectation.

ext/zstd/tests/zstreamtest.c  view on Meta::CPAN

                    size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog);
                    size_t const adjustedDstSize = MIN(cBufferSize - cSize, randomDstSize);
                    outBuff.size = outBuff.pos + adjustedDstSize;
                    remainingToFlush = ZSTD_endStream(zc, &outBuff);
                    CHECK (ZSTD_isError(remainingToFlush), "end error : %s", ZSTD_getErrorName(remainingToFlush));
            }   }
            crcOrig = XXH64_digest(&xxhState);
            cSize = outBuff.pos;
        }

        /* multi - fragments decompression test */
        if (!dictSize /* don't reset if dictionary : could be different */ && (FUZ_rand(&lseed) & 1)) {
            CHECK_Z ( ZSTD_resetDStream(zd) );
        } else {
            CHECK_Z ( ZSTD_initDStream_usingDict(zd, dict, dictSize) );
        }
        {   size_t decompressionResult = 1;
            ZSTD_inBuffer  inBuff = { cBuffer, cSize, 0 };
            ZSTD_outBuffer outBuff= { dstBuffer, dstBufferSize, 0 };
            for (totalGenSize = 0 ; decompressionResult ; ) {
                size_t const readCSrcSize = FUZ_randomLength(&lseed, maxSampleLog);

ext/zstd/tests/zstreamtest.c  view on Meta::CPAN

                }
                cSize = outBuff.pos;
                compressedCrcs[iter] = XXH64(cBuffer, cSize, 0);
                DISPLAYLEVEL(5, "Frame completed : %zu bytes \n", cSize);
            }
            CHECK(!(compressedCrcs[0] == compressedCrcs[1]), "Compression is not deterministic!");
        }

        CHECK(badParameters(zc, savedParams), "CCtx params are wrong");

        /* multi - fragments decompression test */
        if (FUZ_rand(&lseed) & 1) {
            CHECK_Z(ZSTD_DCtx_reset(zd, ZSTD_reset_session_and_parameters));
        }
        if (!dictSize /* don't reset if dictionary : could be different */ && (FUZ_rand(&lseed) & 1)) {
            DISPLAYLEVEL(5, "resetting DCtx (dict:%p) \n", (void const*)dict);
            CHECK_Z( ZSTD_resetDStream(zd) );
        } else {
            if (dictSize)
                DISPLAYLEVEL(5, "using dictionary of size %zu \n", dictSize);
            CHECK_Z( ZSTD_initDStream_usingDict(zd, dict, dictSize) );



( run in 2.766 seconds using v1.01-cache-2.11-cpan-364913b4093 )