summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-30 21:29:20 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-05-02 19:57:21 (EDT)
commit12277cad55c6d3910dbc24ab32baf405f8970d64 (patch)
tree679e522d0231fc64ad5dc3c6fdc9218e46587cfc
parent17db76f6ba811b102935bd8796188996c89db860 (diff)
gzip: Test code
-rw-r--r--src/gzip.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/gzip.c b/src/gzip.c
index 736cbd7..5798bd6 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -178,6 +178,14 @@ int
opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size,
int last)
{
+// 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,98 @@ opkg_opk_gzip_free(struct opkg_opk_gzip *gzip)
free(gzip);
return ret;
}
+
+#if 0 /* 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>
+
+FILE *_out_fp;
+char _out_buffer[8192];
+
+static int
+_write(void *user_data __attribute__((__unused__)), size_t size)
+{
+ if (fwrite(_out_buffer, 1, size, _out_fp) == size) {
+ return OPKG_OPK_OK;
+ } else {
+ return OPKG_OPK_ERROR;
+ }
+}
+
+int
+main(int argc __attribute__((__unused__)), char *argv[])
+{
+ int ret;
+ FILE *in_fp;
+ char in_buffer[512];
+ struct opkg_opk_gzip *gzip;
+ 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(_write, NULL);
+ if (gzip == NULL) {
+ fputs("Error initializing compressor", stderr);
+ ret = EXIT_FAILURE;
+ goto out2;
+ }
+ opkg_opk_gzip_set_write_buffer(gzip, _out_buffer, sizeof(_out_buffer));
+ while ((in_size = fread(in_buffer, 1, sizeof(in_buffer), in_fp)) > 0) {
+ if (opkg_opk_gzip_write(gzip, in_buffer, in_size, 0) !=
+ OPKG_OPK_OK) {
+ fputs("Error compressing", stderr);
+ ret = EXIT_FAILURE;
+ goto out3;
+ }
+ }
+ if (feof(in_fp)) {
+ if (opkg_opk_gzip_write(gzip, in_buffer, in_size, 1) !=
+ OPKG_OPK_END) {
+ fputs("Error finishing compression", 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