diff options
author | Shaun McCance <shaunm@gnome.org> | 2010-04-26 11:24:17 -0500 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2010-04-26 11:24:17 -0500 |
commit | cd6e6383aba8e93f983e298e6044164e0fc19cab (patch) | |
tree | 9db9a546bcbd705f69d3df6cd3912a616d8d1594 /tests/test-magic.c | |
parent | feed213d5298125b026bc0c74d4b3be922b65e0e (diff) | |
download | yelp-cd6e6383aba8e93f983e298e6044164e0fc19cab.tar.gz |
[libyelp] Adding GIO decompressors for bz2, lzma, and magic
Diffstat (limited to 'tests/test-magic.c')
-rw-r--r-- | tests/test-magic.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test-magic.c b/tests/test-magic.c new file mode 100644 index 00000000..9a937991 --- /dev/null +++ b/tests/test-magic.c @@ -0,0 +1,60 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2009 Shaun McCance <shaunm@gnome.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Shaun McCance <shaunm@gnome.org + */ + +#include <config.h> +#include <stdio.h> +#include <string.h> + +#include <gio/gio.h> + +#include "yelp-magic-decompressor.h" + +int +main (int argc, char **argv) +{ + GConverter *converter; + GFile *file; + GFileInputStream *file_stream; + GInputStream *stream; + gchar buf[1024]; + gssize bytes; + + if (argc < 2) { + g_printerr ("Usage: test-magic FILE\n"); + return 1; + } + + g_type_init (); + + file = g_file_new_for_path (argv[1]); + file_stream = g_file_read (file, NULL, NULL); + converter = yelp_magic_decompressor_new (); + stream = g_converter_input_stream_new (file_stream, converter); + + while ((bytes = g_input_stream_read (stream, buf, 1024, NULL, NULL)) > 0) { + gchar *out = g_strndup (buf, bytes); + puts (out); + g_free (out); + } + + return 0; +} |