Improve contrib/blast to return unused bytes. Fix the test code

to report the count of unused bytes at the end correctly.  Add the
ability to provide initial input to blast().
This commit is contained in:
Mark Adler
2013-08-24 01:53:31 -07:00
parent 89e335abb4
commit 799c87c0d8
2 changed files with 42 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
/* blast.h -- interface for blast.c
Copyright (C) 2003, 2012 Mark Adler
version 1.2, 24 Oct 2012
Copyright (C) 2003, 2012, 2013 Mark Adler
version 1.3, 24 Aug 2013
This software is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
@@ -42,7 +42,8 @@ typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len);
*/
int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow,
unsigned *left, unsigned char **in);
/* Decompress input to output using the provided infun() and outfun() calls.
* On success, the return value of blast() is zero. If there is an error in
* the source data, i.e. it is not in the proper format, then a negative value
@@ -55,12 +56,19 @@ int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
* an input error. (blast() only asks for input if it needs it.) inhow is for
* use by the application to pass an input descriptor to infun(), if desired.
*
* If left and in are not NULL and *left is not zero when blast() is called,
* then the *left bytes are *in are consumed for input before infun() is used.
*
* The output function is invoked: err = outfun(how, buf, len), where the bytes
* to be written are buf[0..len-1]. If err is not zero, then blast() returns
* with an output error. outfun() is always called with len <= 4096. outhow
* is for use by the application to pass an output descriptor to outfun(), if
* desired.
*
* If there is any unused input, *left is set to the number of bytes that were
* read and *in points to them. Otherwise *left is set to zero and *in is set
* to NULL. If left or in are NULL, then they are not set.
*
* The return codes are:
*
* 2: ran out of input before completing decompression