return 0;
}
+/* @return provides a minimum amount of data remaining to be flushed from internal buffers
+ */
size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
ZSTD_outBuffer* output,
ZSTD_inBuffer* input,
/* transparent initialization stage */
if (cctx->streamStage == zcss_init) {
+ size_t const inputSize = input->size - input->pos; /* no obligation to start from pos==0 */
if ( (cctx->requestedParams.inBufferMode == ZSTD_bm_stable) /* input is presumed stable, across invocations */
- && (endOp == ZSTD_e_continue) /* more to come */
- && (input->pos < ZSTD_BLOCKSIZE_MAX) ) { /* not even reached one block yet */
+ && (endOp == ZSTD_e_continue) /* no flush requested, more input to come */
+ && (inputSize < ZSTD_BLOCKSIZE_MAX) ) { /* not even reached one block yet */
+ /* just wait, allows lazy adaptation of compression parameters */
cctx->expectedInBuffer = *input;
- return (ZSTD_BLOCKSIZE_MAX - input->pos); /* don't do anything : allows lazy adaptation of compression parameters */
+ return ZSTD_FRAMEHEADERSIZE_MIN(cctx->requestedParams.format); /* at least some header to produce */
}
- FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, endOp, input->size), "CompressStream2 initialization failed");
+ FORWARD_IF_ERROR(ZSTD_CCtx_init_compressStream2(cctx, endOp, inputSize), "CompressStream2 initialization failed");
ZSTD_setBufferExpectations(cctx, output, input); /* Set initial buffer expectations now that we've initialized */
}
/* end of transparent initialization stage */
* memory. However, compression WILL fail if conditions are not respected.
*
* WARNING: The data in the ZSTD_inBuffer in the range [src, src + pos) MUST
- * not be modified during compression or it sill result in data corruption.
+ * not be modified during compression or it will result in data corruption.
* This is because zstd needs to reference data in the ZSTD_inBuffer to find
* matches. Normally zstd maintains its own window buffer for this purpose,
* but passing this flag tells zstd to rely on user provided buffer instead.
DISPLAYLEVEL(3, "test%3i : ZSTD_c_stableInBuffer compatibility with compressStream, flushStream and endStream : ", testNb++);
CHECK_Z( ZSTD_initCStream(cctx, 1) );
CHECK_Z( ZSTD_CCtx_setParameter(cctx, ZSTD_c_stableInBuffer, 1) );
- in.src = CNBuffer;
- in.size = 100;
- in.pos = 0;
- { ZSTD_outBuffer outBuf;
+ { ZSTD_inBuffer inBuf;
+ ZSTD_outBuffer outBuf;
+ inBuf.src = CNBuffer;
+ inBuf.size = 100;
+ inBuf.pos = 0;
outBuf.dst = (char*)(compressedBuffer)+cSize;
outBuf.size = ZSTD_compressBound(500);
outBuf.pos = 0;
- CHECK_Z( ZSTD_compressStream(cctx, &outBuf, &in) );
- in.size = 200;
- CHECK_Z( ZSTD_compressStream(cctx, &outBuf, &in) );
+ CHECK_Z( ZSTD_compressStream(cctx, &outBuf, &inBuf) );
+ inBuf.size = 200;
+ CHECK_Z( ZSTD_compressStream(cctx, &outBuf, &inBuf) );
CHECK_Z( ZSTD_flushStream(cctx, &outBuf) );
- in.size = 300;
- CHECK_Z( ZSTD_compressStream(cctx, &outBuf, &in) );
- if (ZSTD_endStream(cctx, &outBuf) != 0) goto _output_error; /* error, or some data not flushed */
+ inBuf.size = 300;
+ CHECK_Z( ZSTD_compressStream(cctx, &outBuf, &inBuf) );
+ CHECK(ZSTD_endStream(cctx, &outBuf) != 0, "compression should be successful and fully flushed");
}
DISPLAYLEVEL(3, "OK \n");
CHECK_Z(ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters));
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1));
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_stableOutBuffer, 1));
+ in.src = CNBuffer;
in.pos = out.pos = 0;
in.size = MIN(CNBufferSize, 10);
out.size = compressedBufferSize;