Blob
1 #include <u.h>2 #include <libc.h>3 #include <flate.h>5 typedef struct Block Block;7 struct Block8 {9 uchar *pos;10 uchar *limit;11 };13 static int14 blread(void *vb, void *buf, int n)15 {16 Block *b;18 b = vb;19 if(n > b->limit - b->pos)20 n = b->limit - b->pos;21 memmove(buf, b->pos, n);22 b->pos += n;23 return n;24 }26 static int27 blwrite(void *vb, void *buf, int n)28 {29 Block *b;31 b = vb;33 if(n > b->limit - b->pos)34 n = b->limit - b->pos;35 memmove(b->pos, buf, n);36 b->pos += n;37 return n;38 }40 int41 deflateblock(uchar *dst, int dsize, uchar *src, int ssize, int level, int debug)42 {43 Block bd, bs;44 int ok;46 bs.pos = src;47 bs.limit = src + ssize;49 bd.pos = dst;50 bd.limit = dst + dsize;52 ok = deflate(&bd, blwrite, &bs, blread, level, debug);53 if(ok != FlateOk)54 return ok;55 return bd.pos - dst;56 }