diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 12b5a32e..1f274622 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2567,6 +2567,24 @@ size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs, ZSTD_compress2(zc, dst, dstCapacity, src, srcSize); ZSTD_customFree(dst, ZSTD_defaultCMem); + + if (format == ZSTD_sf_noBlockDelimiters) { + /* Merge the dummy block delimiters */ + size_t i = 0; + size_t totalSeqs = zc->seqCollector.seqIndex; + for (; i < totalSeqs; ++i) { + if (seqCollector.seqStart[i].offset == 0 && seqCollector.seqStart[i].matchLength == 0) { + /* Merge the block boundary or last literals */ + if (i != totalSeqs-1) { + /* Add last literals to next sequence, then "delete" this sequence */ + seqCollector.seqStart[i+1].litLength += seqCollector.seqStart[i].litLength; + memmove(seqCollector.seqStart+i, seqCollector.seqStart+i+1, (totalSeqs-i-1)*sizeof(ZSTD_sequence)); + } + totalSeqs--; + } + } + zc->seqCollector.seqIndex = totalSeqs; + } return zc->seqCollector.seqIndex; } diff --git a/lib/zstd.h b/lib/zstd.h index 3809a033..4158c4ac 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -1309,9 +1309,9 @@ typedef enum { * * If invoked with ZSTD_sf_noBlockDelimiters, sequences will still be generated * on a per-block basis, but any last literals of a block will be merged into the - * last literals of the first sequence in the next block with the exception of the - * final segment of last literals. As such, the final generated result has no - * explicit representation of block boundaries. + * last literals of the first sequence in the next block. + * As such, the final generated result has no explicit representation of block boundaries, + * and the final last literals segment is not represented in the sequences. * * zc can be used to insert custom compression params. * This function invokes ZSTD_compress2