diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gzip.c | 82 |
1 files changed, 82 insertions, 0 deletions
@@ -171,6 +171,14 @@ _opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size, { size_t len; +// memcpy(gzip->buffer, record, size); +// gzip->write_func(gzip->user_data, size); +// if (last == 0) { +// return OPKG_OPK_OK; +// } else { +// return OPKG_OPK_END; +// } + /* Sanity check */ if (gzip->dir != _OPKG_OPK_GZIP_DIR_WRITE) { return OPKG_OPK_ERROR; @@ -240,3 +248,77 @@ opkg_opk_gzip_free(struct opkg_opk_gzip *gzip) free(gzip); return ret; } + +#if 1 /* Test code */ + +/* + * echo 2.0 >debian-binary + * tar -cf test.tar debian-binary # if using GNU tar... + * truncate -s 2048 test.tar # ...remove extra trailer records + * busybox tar -cf test.tar debian-binary # or just use BB tar + * flags=$(pkg-config --cflags --libs zlib) + * gcc -Wall -Wextra -pedantic -g -O0 -o gzip src/gzip.c ${flags} + * ./gzip test.tar test.tar.gz + * gunzip -c test.tar.gz 1>test.tar.ungz + * ls -l test.tar* # test.tar and test.tar.ungz should be 2048 bytes + * # test.tar.gz should be 108 bytes or so + * cmp test.tar test.tar.ungz # should be quiet + * bvi test.tar.gz # compare to RFC 1952 + * gzip -9cn test.tar 1>test.tar.gzip + * ls -l test.tar.gz* # both should be 108 bytes or so + * cmp test.tar.gz* # should be quiet + */ + +#include <stdio.h> + +int +main(int argc __attribute__((__unused__)), char *argv[]) +{ + int ret; + FILE *in_fp; + FILE *out_fp; + struct opkg_opk_gzip *gzip; + char in_buffer[512]; + size_t in_size; + + ret = EXIT_SUCCESS; + in_fp = fopen(argv[1], "rb"); + if (in_fp == NULL) { + fputs("Error opening input", stderr); + ret = EXIT_FAILURE; + goto out0; + } + out_fp = fopen(argv[2], "wb"); + if (out_fp == NULL) { + fputs("Error opening output", stderr); + ret = EXIT_FAILURE; + goto out1; + } + gzip = opkg_opk_gzip_init_write(out_fp); + if (gzip == NULL) { + fputs("Error initializing compressor", stderr); + ret = EXIT_FAILURE; + goto out2; + } + while ((in_size = fread(in_buffer, 1, sizeof(in_buffer), in_fp)) > 0) { + if (opkg_opk_gzip_write(gzip, in_buffer, in_size) != + OPKG_OPK_OK) { + fputs("Error compressing", stderr); + ret = EXIT_FAILURE; + goto out3; + } + } + out3: + if (opkg_opk_gzip_free(gzip) != OPKG_OPK_OK) { + fputs("Error freeing compressor", stderr); + ret = EXIT_FAILURE; + } + out2: + fclose(out_fp); + out1: + fclose(in_fp); + out0: + return ret; +} + +#endif |