]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2016 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions | |
6 | are met: | |
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | * Redistributions in binary form must reproduce the above copyright | |
10 | notice, this list of conditions and the following disclaimer in | |
11 | the documentation and/or other materials provided with the | |
12 | distribution. | |
13 | * Neither the name of Intel Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | **********************************************************************/ | |
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | #include <assert.h> | |
32 | #include "igzip_lib.h" | |
33 | ||
34 | #define BUF_SIZE 8192 | |
224ce89b WB |
35 | #ifndef LEVEL |
36 | # define LEVEL 0 | |
37 | #else | |
38 | # define LEVEL 1 | |
39 | #endif | |
7c673cae FG |
40 | |
41 | struct isal_zstream stream; | |
42 | ||
43 | int main(int argc, char *argv[]) | |
44 | { | |
45 | uint8_t inbuf[BUF_SIZE], outbuf[BUF_SIZE]; | |
46 | FILE *in, *out; | |
47 | ||
48 | if (argc != 3) { | |
49 | fprintf(stderr, "Usage: igzip_example infile outfile\n"); | |
50 | exit(0); | |
51 | } | |
52 | in = fopen(argv[1], "rb"); | |
53 | if (!in) { | |
54 | fprintf(stderr, "Can't open %s for reading\n", argv[1]); | |
55 | exit(0); | |
56 | } | |
57 | out = fopen(argv[2], "wb"); | |
58 | if (!out) { | |
59 | fprintf(stderr, "Can't open %s for writing\n", argv[2]); | |
60 | exit(0); | |
61 | } | |
62 | ||
224ce89b | 63 | printf("igzip_example\nWindow Size: %d K\n", IGZIP_HIST_SIZE / 1024); |
7c673cae FG |
64 | fflush(0); |
65 | ||
66 | isal_deflate_init(&stream); | |
67 | stream.end_of_stream = 0; | |
68 | stream.flush = NO_FLUSH; | |
69 | ||
224ce89b WB |
70 | if (LEVEL == 1) { |
71 | stream.level = 1; | |
72 | stream.level_buf = malloc(ISAL_DEF_LVL1_DEFAULT); | |
73 | stream.level_buf_size = ISAL_DEF_LVL1_DEFAULT; | |
74 | if (stream.level_buf == 0) { | |
75 | printf("Failed to allocate level compression buffer\n"); | |
76 | exit(0); | |
77 | } | |
78 | } | |
79 | ||
7c673cae FG |
80 | do { |
81 | stream.avail_in = (uint32_t) fread(inbuf, 1, BUF_SIZE, in); | |
224ce89b | 82 | stream.end_of_stream = feof(in) ? 1 : 0; |
7c673cae FG |
83 | stream.next_in = inbuf; |
84 | do { | |
85 | stream.avail_out = BUF_SIZE; | |
86 | stream.next_out = outbuf; | |
87 | ||
88 | isal_deflate(&stream); | |
89 | ||
90 | fwrite(outbuf, 1, BUF_SIZE - stream.avail_out, out); | |
91 | } while (stream.avail_out == 0); | |
92 | ||
93 | assert(stream.avail_in == 0); | |
94 | } while (stream.internal_state.state != ZSTATE_END); | |
95 | ||
96 | fclose(out); | |
97 | fclose(in); | |
98 | ||
99 | printf("End of igzip_example\n\n"); | |
100 | return 0; | |
101 | } |