Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add an extra sync marker between independent blocks.
This forces two sync markers between independent blocks, giving a
nine-byte signature 00 00 ff ff 00 00 00 ff ff to search for when
processing compressed data in parallel.
  • Loading branch information
madler committed May 30, 2016
1 parent b7d1db4 commit 374d167
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions pigz.c
Expand Up @@ -1607,7 +1607,7 @@ local void compress_thread(void *dummy)

/* add enough empty blocks to get to a byte boundary */
(void)deflatePending(&strm, Z_NULL, &bits);
if (bits & 1)
if ((bits & 1) || !g.setdict)
deflate_engine(&strm, job->out, Z_SYNC_FLUSH);
else if (bits & 7) {
do { /* add static empty blocks */
Expand All @@ -1620,6 +1620,8 @@ local void compress_thread(void *dummy)
#else
deflate_engine(&strm, job->out, Z_SYNC_FLUSH);
#endif
if (!g.setdict) /* two markers when independent */
deflate_engine(&strm, job->out, Z_FULL_FLUSH);
}
else
deflate_engine(&strm, job->out, Z_FINISH);
Expand All @@ -1641,8 +1643,8 @@ local void compress_thread(void *dummy)
job->out->len += outsize;
if (left || job->more) {
bits &= 7;
if (bits & 1) {
if (bits == 7)
if ((bits & 1) || !g.setdict) {
if (bits == 0 || bits > 5)
job->out->buf[job->out->len++] = 0;
job->out->buf[job->out->len++] = 0;
job->out->buf[job->out->len++] = 0;
Expand All @@ -1656,6 +1658,13 @@ local void compress_thread(void *dummy)
bits += 2;
} while (bits < 8);
}
if (!g.setdict) { /* two markers when independent */
job->out->buf[job->out->len++] = 0;
job->out->buf[job->out->len++] = 0;
job->out->buf[job->out->len++] = 0;
job->out->buf[job->out->len++] = 0xff;
job->out->buf[job->out->len++] = 0xff;
}
}
temp->len += len;
}
Expand Down Expand Up @@ -2185,7 +2194,7 @@ local void single_compress(int reset)

DEFLATE_WRITE(Z_BLOCK);
(void)deflatePending(strm, Z_NULL, &bits);
if (bits & 1)
if ((bits & 1) || !g.setdict)
DEFLATE_WRITE(Z_SYNC_FLUSH);
else if (bits & 7) {
do {
Expand All @@ -2198,6 +2207,8 @@ local void single_compress(int reset)
#else
DEFLATE_WRITE(Z_SYNC_FLUSH);
#endif
if (!g.setdict) /* two markers when independent */
DEFLATE_WRITE(Z_FULL_FLUSH);
}
else
DEFLATE_WRITE(Z_FINISH);
Expand All @@ -2219,24 +2230,27 @@ local void single_compress(int reset)
in + hist, off - hist, (off - hist) + got,
&bits, &out, &outsize);
bits &= 7;
if ((more || left) && bits) {
if (bits & 1) {
if (more || left) {
if ((bits & 1) || !g.setdict) {
writen(g.outd, out, outsize);
if (bits == 7)
if (bits == 0 || bits > 5)
writen(g.outd, (unsigned char *)"\0", 1);
writen(g.outd, (unsigned char *)"\0\0\xff\xff", 4);
}
else {
assert(outsize > 0);
writen(g.outd, out, outsize - 1);
do {
out[outsize - 1] += 2 << bits;
writen(g.outd, out + outsize - 1, 1);
out[outsize - 1] = 0;
bits += 2;
} while (bits < 8);
if (bits)
do {
out[outsize - 1] += 2 << bits;
writen(g.outd, out + outsize - 1, 1);
out[outsize - 1] = 0;
bits += 2;
} while (bits < 8);
writen(g.outd, out + outsize - 1, 1);
}
if (!g.setdict) /* two markers when independent */
writen(g.outd, (unsigned char *)"\0\0\0\xff\xff", 5);
}
else
writen(g.outd, out, outsize);
Expand Down

0 comments on commit 374d167

Please sign in to comment.