Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Test application to test buffer-to-buffer decoding |
| 3 | * |
| 4 | * Author: Lasse Collin <lasse.collin@tukaani.org> |
| 5 | * |
| 6 | * This file has been put into the public domain. |
| 7 | * You can do whatever you want with this file. |
| 8 | */ |
| 9 | |
| 10 | #include <stdbool.h> |
| 11 | #include <stdio.h> |
| 12 | #include <string.h> |
| 13 | #include "xz.h" |
| 14 | |
| 15 | #define BUFFER_SIZE (1024 * 1024) |
| 16 | |
| 17 | static uint8_t in[BUFFER_SIZE]; |
| 18 | static uint8_t out[BUFFER_SIZE]; |
| 19 | |
| 20 | int main(void) |
| 21 | { |
| 22 | struct xz_buf b; |
| 23 | struct xz_dec *s; |
| 24 | enum xz_ret ret; |
| 25 | |
| 26 | xz_crc32_init(); |
| 27 | |
Lasse Collin | c4c6f5c | 2010-06-09 12:22:35 +0300 | [diff] [blame] | 28 | s = xz_dec_init(XZ_SINGLE, 0); |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 29 | if (s == NULL) { |
Du Huanpeng | e75f4eb | 2015-11-03 08:29:27 +0800 | [diff] [blame] | 30 | fputs("Initialization failed\n", stderr); |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 31 | return 1; |
| 32 | } |
| 33 | |
| 34 | b.in = in; |
| 35 | b.in_pos = 0; |
| 36 | b.in_size = fread(in, 1, sizeof(in), stdin); |
Du Huanpeng | e75f4eb | 2015-11-03 08:29:27 +0800 | [diff] [blame] | 37 | |
Lasse Collin | bcc4b36 | 2009-03-22 13:12:47 +0200 | [diff] [blame] | 38 | b.out = out; |
| 39 | b.out_pos = 0; |
| 40 | b.out_size = sizeof(out); |
| 41 | |
| 42 | ret = xz_dec_run(s, &b); |
| 43 | xz_dec_end(s); |
| 44 | |
| 45 | fwrite(out, 1, b.out_pos, stdout); |
| 46 | fprintf(stderr, "%d\n", ret); |
| 47 | |
| 48 | return 0; |
| 49 | } |