shithub: pdffs

ref: 1ecdb9da0d3e8ae0e6b6c49d4cfdea72355261a0
dir: /f_flate.c/

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

/* 7.4.4 FlateDecode filter */

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;
}

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

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

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

	return unpredict(aux, bo);
}

Filter filterFlate = {
	.name = "FlateDecode",
	.readall = flreadall,
	.open = flopenpredict,
	.close = flclosepredict,
};