shithub: pdffs

ref: ecd40a88198f1a03b0e87a4f3066f944f09cf0d8
dir: /f_flate.c/

View raw version
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <flate.h>
#include "pdf.h"

static int
bw(void *aux, void *d, int n)
{
	return bufput(aux, d, n);
}

static int
bget(void *aux)
{
	uchar c;

	return bufget(aux, &c, 1) == 1 ? c : -1;
}

int
fFlate(void *aux, Buffer *bi, Buffer *bo)
{
	int r;

	USED(aux);

	do{
		r = inflatezlib(bo, bw, bi, bget);
	}while(r == FlateOk && !bufeof(bi));

	if(r != FlateOk){
		werrstr("%s", flateerr(r));
		return -1;
	}

	return 0;
}