/* Flushes pending bits and sends the trailer for stream <strm> into buffer
* <buf> if needed. When it's done, the stream state is updated to SLZ_ST_END.
* It returns the number of bytes emitted. The trailer consists in flushing the
- * possibly pending bits from the queue (up to 24 bits), rounding to the next
- * byte, then 4 bytes for the CRC when doing zlib/gzip, then another 4 bytes
- * for the input length for gzip. That may about to 4+4+4 = 12 bytes, that the
- * caller must ensure are available before calling the function. Note that if
- * the initial header was never sent, it will be sent first as well (up to 10
- * extra bytes).
+ * possibly pending bits from the queue, the possible EOB and the final empty
+ * block, rounding to the next byte, then 4 bytes for the CRC when doing
+ * zlib/gzip, then another 4 bytes for the input length for gzip. That may
+ * amount to 6+4+4 = 14 bytes, that the caller must ensure are available before
+ * calling the function. Note that if the initial header was never sent, it
+ * will be sent first as well (up to 10 extra bytes).
*/
static inline int slz_finish(struct slz_stream *strm, void *buf)
{
* empty literal block to byte-align the output, allowing to completely flush
* the queue. Note that if the initial header was never sent, it will be sent
* first as well (0, 2 or 10 extra bytes). This requires that the output buffer
- * still has this plus the size of the queue available (up to 4 bytes), plus
- * one byte for (BFINAL,BTYPE), plus 4 bytes for LEN+NLEN, or a total of 19
+ * still has this plus the 6 bytes needed to flush the queue, the possible EOB
+ * and the (BFINAL,BTYPE) bits, plus 4 bytes for LEN+NLEN, or a total of 20
* bytes in the worst case. The number of bytes emitted is returned. It is
* guaranteed that the queue is empty on return. This may cause some overhead
* by adding needless 5-byte blocks if called to often.
/* Flushes any pending data for stream <strm> into buffer <buf>, then emits an
* empty literal block to byte-align the output, allowing to completely flush
* the queue. This requires that the output buffer still has the size of the
- * queue available (up to 4 bytes), plus one byte for (BFINAL,BTYPE), plus 4
- * bytes for LEN+NLEN, or a total of 9 bytes in the worst case. The number of
- * bytes emitted is returned. It is guaranteed that the queue is empty on
- * return. This may cause some overhead by adding needless 5-byte blocks if
- * called to often.
+ * queue (up to 31 bits when using the 64-bit queue), plus a possible EOB (7
+ * bits), plus (BFINAL,BTYPE) (3 bits), which once rounded up to the next byte
+ * make 6 bytes, plus 4 bytes for LEN+NLEN, or a total of 10 bytes in the worst
+ * case. The number of bytes emitted is returned. It is guaranteed that the
+ * queue is empty on return. This may cause some overhead by adding needless
+ * 5-byte blocks if called to often.
*/
int slz_rfc1951_flush(struct slz_stream *strm, unsigned char *buf)
{
/* Flushes any pending for stream <strm> into buffer <buf>, then sends BTYPE=1
* and BFINAL=1 if needed. The stream ends in SLZ_ST_DONE. It returns the number
* of bytes emitted. The trailer consists in flushing the possibly pending bits
- * from the queue (up to 7 bits), then possibly EOB (7 bits), then 3 bits, EOB,
- * a rounding to the next byte, which amounts to a total of 4 bytes max, that
- * the caller must ensure are available before calling the function.
+ * from the queue (up to 31 bits when using the 64-bit queue), then possibly
+ * EOB (7 bits), then 3 bits, EOB, a rounding to the next byte, which amounts
+ * to a total of 6 bytes max, that the caller must ensure are available before
+ * calling the function.
*/
int slz_rfc1951_finish(struct slz_stream *strm, unsigned char *buf)
{
* empty literal block to byte-align the output, allowing to completely flush
* the queue. Note that if the initial header was never sent, it will be sent
* first as well (10 extra bytes). This requires that the output buffer still
- * has this plus the size of the queue available (up to 4 bytes), plus one byte
- * for (BFINAL,BTYPE), plus 4 bytes for LEN+NLEN, or a total of 19 bytes in the
- * worst case. The number of bytes emitted is returned. It is guaranteed that
- * the queue is empty on return. This may cause some overhead by adding
+ * has this plus the 6 bytes needed to flush the queue, the possible EOB and
+ * the (BFINAL,BTYPE) bits, plus 4 bytes for LEN+NLEN, or a total of 20 bytes
+ * in the worst case. The number of bytes emitted is returned. It is guaranteed
+ * that the queue is empty on return. This may cause some overhead by adding
* needless 5-byte blocks if called to often.
*/
int slz_rfc1952_flush(struct slz_stream *strm, unsigned char *buf)
/* Flushes pending bits and sends the gzip trailer for stream <strm> into
* buffer <buf>. When it's done, the stream state is updated to SLZ_ST_END. It
* returns the number of bytes emitted. The trailer consists in flushing the
- * possibly pending bits from the queue (up to 24 bits), rounding to the next
- * byte, then 4 bytes for the CRC and another 4 bytes for the input length.
- * That may about to 4+4+4 = 12 bytes, that the caller must ensure are
- * available before calling the function. Note that if the initial header was
- * never sent, it will be sent first as well (10 extra bytes).
+ * possibly pending bits from the queue, the possible EOB and the final empty
+ * block, rounding to the next byte, then 4 bytes for the CRC and another 4
+ * bytes for the input length. That may amount to 6+4+4 = 14 bytes, that the
+ * caller must ensure are available before calling the function. Note that if
+ * the initial header was never sent, it will be sent first as well (10 extra
+ * bytes).
*/
int slz_rfc1952_finish(struct slz_stream *strm, unsigned char *buf)
{
return 0;
}
-/* Flushes any pending data for stream <strm> into buffer <buf>, then emits an
- * empty literal block to byte-align the output, allowing to completely flush
- * the queue. Note that if the initial header was never sent, it will be sent
- * first as well (2 extra bytes). This requires that the output buffer still
- * has this plus the size of the queue available (up to 4 bytes), plus one byte
- * for (BFINAL,BTYPE), plus 4 bytes for LEN+NLEN, or a total of 11 bytes in the
- * worst case. The number of bytes emitted is returned. It is guaranteed that
- * the queue is empty on return. This may cause some overhead by adding
- * needless 5-byte blocks if called to often.
+/* Flushes pending bits and sends the gzip trailer for stream <strm> into
+ * buffer <buf>. When it's done, the stream state is updated to SLZ_ST_END. It
+ * returns the number of bytes emitted. The trailer consists in flushing the
+ * possibly pending bits from the queue, the possible EOB and the final empty
+ * block, rounding to the next byte, then 4 bytes for the CRC. That may amount
+ * to 6+4 = 10 bytes, that the caller must ensure are available before calling
+ * the function. Note that if the initial header was never sent, it will be
+ * sent first as well (2 extra bytes).
*/
int slz_rfc1950_flush(struct slz_stream *strm, unsigned char *buf)
{
/* Flushes pending bits and sends the gzip trailer for stream <strm> into
* buffer <buf>. When it's done, the stream state is updated to SLZ_ST_END. It
* returns the number of bytes emitted. The trailer consists in flushing the
- * possibly pending bits from the queue (up to 24 bits), rounding to the next
- * byte, then 4 bytes for the CRC. That may about to 4+4 = 8 bytes, that the
- * caller must ensure are available before calling the function. Note that if
- * the initial header was never sent, it will be sent first as well (2 extra
- * bytes).
+ * possibly pending bits from the queue, the possible EOB and the final empty
+ * block, rounding to the next byte, then 4 bytes for the CRC. That may amount
+ * to 6+4 = 10 bytes, that the caller must ensure are available before calling
+ * the function. Note that if the initial header was never sent, it will be
+ * sent first as well (2 extra bytes).
*/
int slz_rfc1950_finish(struct slz_stream *strm, unsigned char *buf)
{