aboutsummaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2012-01-07 09:54:40 -0800
committerMark Adler <madler@alumni.caltech.edu>2012-01-07 14:03:07 -0800
commit263b1a05b04e442896d7941f87d022a2f35a9220 (patch)
tree465a40cf714deb72b89504c1f3f9665db3feafd6 /deflate.c
parent19761b8506f15d6eeeb6ccfab33a11abce0f40e7 (diff)
downloadzlib-263b1a05b04e442896d7941f87d022a2f35a9220.tar.gz
zlib-263b1a05b04e442896d7941f87d022a2f35a9220.tar.bz2
zlib-263b1a05b04e442896d7941f87d022a2f35a9220.zip
Allow deflatePrime() to insert bits in the middle of a stream.
This allows the insertion of multiple empty static blocks for the purpose of efficiently bringing a stream to a byte boundary.
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/deflate.c b/deflate.c
index eed6ed8..12fbd5a 100644
--- a/deflate.c
+++ b/deflate.c
@@ -1,5 +1,5 @@
1/* deflate.c -- compress data using the deflation algorithm 1/* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2011 Jean-loup Gailly and Mark Adler 2 * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
@@ -52,7 +52,7 @@
52#include "deflate.h" 52#include "deflate.h"
53 53
54const char deflate_copyright[] = 54const char deflate_copyright[] =
55 " deflate 1.2.5.3 Copyright 1995-2011 Jean-loup Gailly and Mark Adler "; 55 " deflate 1.2.5.3 Copyright 1995-2012 Jean-loup Gailly and Mark Adler ";
56/* 56/*
57 If you use the zlib library in a product, an acknowledgment is welcome 57 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot 58 in the documentation of your product. If for some reason you cannot
@@ -464,9 +464,23 @@ int ZEXPORT deflatePrime (strm, bits, value)
464 int bits; 464 int bits;
465 int value; 465 int value;
466{ 466{
467 deflate_state *s;
468 int put;
469
467 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 470 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
468 strm->state->bi_valid = bits; 471 s = strm->state;
469 strm->state->bi_buf = (ush)(value & ((1 << bits) - 1)); 472 if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
473 return Z_BUF_ERROR;
474 do {
475 put = Buf_size - s->bi_valid;
476 if (put > bits)
477 put = bits;
478 s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
479 s->bi_valid += put;
480 _tr_flush_bits(s);
481 value >>= put;
482 bits -= put;
483 } while (bits);
470 return Z_OK; 484 return Z_OK;
471} 485}
472 486