]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: Added file uncompression support for test-compression
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Oct 2016 15:31:53 +0000 (18:31 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 25 Oct 2016 18:01:22 +0000 (21:01 +0300)
This can be useful for debugging.

src/lib-compression/test-compression.c

index b84a06dea09b1322255908830a9a238bcf8bde4b..8c70923ce8a1eeb35ec445a63c08a5e568c867ec 100644 (file)
@@ -94,6 +94,29 @@ static void test_compression(void)
        }
 }
 
+static void test_uncompress_file(const char *path)
+{
+       const struct compression_handler *handler;
+       struct istream *input, *file_input;
+       const unsigned char *data;
+       size_t size;
+
+       handler = compression_lookup_handler_from_ext(path);
+       if (handler == NULL)
+               i_fatal("Can't detect compression algorithm from path %s", path);
+       if (handler->create_istream == NULL)
+               i_fatal("Support not compiled in for %s", handler->name);
+
+       file_input = i_stream_create_file(path, IO_BLOCK_SIZE);
+       input = handler->create_istream(file_input, 1);
+       while (i_stream_read_more(input, &data, &size) > 0) {
+               if (write(STDOUT_FILENO, data, size) < 0)
+                       break;
+               i_stream_skip(input, size);
+       }
+       i_stream_destroy(&input);
+}
+
 static void test_compress_file(const char *in_path, const char *out_path)
 {
        const struct compression_handler *handler;
@@ -161,6 +184,10 @@ int main(int argc, char *argv[])
                test_compression,
                NULL
        };
+       if (argc == 2) {
+               test_uncompress_file(argv[1]);
+               return 0;
+       }
        if (argc == 3) {
                test_compress_file(argv[1], argv[2]);
                return 0;