1 #include <string.h>
2 #include "../gsk.h"
3 #include "../zlib/gskzlibinflator.h"
4 #include "../zlib/gskzlibdeflator.h"
5 
6 
7 static gboolean use_gzip = FALSE;
8 static gboolean compress = FALSE;
9 static int flush_millis = -1;
10 static gint compress_level = -1;
11 
12 
13 static GOptionEntry entries[] =
14 {
15   { "gzip", 'g', 0, G_OPTION_ARG_NONE, &use_gzip, "use gzip format (as opposed to deflate format)", NULL },
16   { "compress", 'c', 0, G_OPTION_ARG_NONE, &compress, "compress (instead of decompressing)", NULL },
17   { "flush-millis", 'f', 0, G_OPTION_ARG_INT, &flush_millis, "flush timeout", "MS" },
18   { "compress-level", 0, 0, G_OPTION_ARG_INT, &compress_level, "compression level", NULL },
19   { NULL, 0, 0, 0, NULL, NULL, NULL },
20 };
21 
22 int
main(int argc,char ** argv)23 main (int argc, char **argv)
24 {
25   GskStream *in, *zlib, *out;
26   GOptionContext *context;
27   GError *error = NULL;
28   gsk_init_without_threads (&argc, &argv);
29 
30   context = g_option_context_new ("test-zlib-stream");
31   g_option_context_add_main_entries (context, entries, NULL);
32   if (!g_option_context_parse (context, &argc, &argv, &error))
33     g_error ("error parsing options: %s", error->message);
34 
35   in = gsk_stream_fd_new_auto (0);
36   if (compress)
37     zlib = gsk_zlib_deflator_new2 (compress_level,
38                                    flush_millis,
39                                    use_gzip);
40   else
41     zlib = gsk_zlib_inflator_new2 (use_gzip);
42   out = gsk_stream_fd_new_auto (1);
43   gsk_stream_attach (in, zlib, NULL);
44   gsk_stream_attach (zlib, out, NULL);
45   g_object_weak_ref (G_OBJECT (zlib), (GWeakNotify) gsk_main_quit, NULL);
46   g_object_unref (zlib);
47   return gsk_main_run ();
48 }
49