From 59b029effe50fbd2b776f2e1739daed8de2738fd Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 1 Jan 2020 23:22:40 +0100 Subject: [PATCH] PackBits_pack_buffer() --- src/packbits.c | 13 +++++++++++++ src/packbits.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/packbits.c b/src/packbits.c index 7cb51498..87bf2fa4 100644 --- a/src/packbits.c +++ b/src/packbits.c @@ -180,3 +180,16 @@ int PackBits_pack_flush(T_PackBits_data * data) } return data->output_count; } + +int PackBits_pack_buffer(FILE * f, const byte * buffer, size_t size) +{ + T_PackBits_data pb_data; + + PackBits_pack_init(&pb_data, f); + while (size-- > 0) + { + if (PackBits_pack_add(&pb_data, *buffer++)) + return -1; + } + return PackBits_pack_flush(&pb_data); +} diff --git a/src/packbits.h b/src/packbits.h index 060ba1fd..400e8277 100644 --- a/src/packbits.h +++ b/src/packbits.h @@ -70,4 +70,11 @@ int PackBits_pack_add(T_PackBits_data * data, byte b); */ int PackBits_pack_flush(T_PackBits_data * data); +/** + * Pack a full buffer to FILE + * @param f FILE output or NULL (for no output) + * @return -1 for error, or the size of the packed stream so far + */ +int PackBits_pack_buffer(FILE * f, const byte * buffer, size_t size); + #endif