1
1
// Copied from https://gist.github.com/arq5x/5315739 for test purposes
2
2
3
+ #include < assert.h>
3
4
#include < stdio.h>
4
5
#include < string.h> // for strlen
5
- # include < assert.h >
6
+
6
7
#include " zlib.h"
7
8
8
- // adapted from: http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c
9
- int main ( int argc, char * argv[])
10
- {
9
+ // adapted from:
10
+ // http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c
11
+ int main ( int argc, char *argv[]) {
11
12
// original string len = 36
12
13
char a[50 ] = " Hello Hello Hello Hello Hello Hello!" ;
13
14
@@ -17,11 +18,9 @@ int main(int argc, char* argv[])
17
18
// placeholder for the UNcompressed (inflated) version of "b"
18
19
char c[50 ];
19
20
20
-
21
21
printf (" Uncompressed size is: %lu\n " , strlen (a));
22
22
printf (" Uncompressed string is: %s\n " , a);
23
23
24
-
25
24
printf (" \n ----------\n\n " );
26
25
27
26
// STEP 1.
@@ -33,10 +32,11 @@ int main(int argc, char* argv[])
33
32
defstream.zfree = Z_NULL;
34
33
defstream.opaque = Z_NULL;
35
34
// setup "a" as the input and "b" as the compressed output
36
- defstream.avail_in = (uInt)strlen (a)+1 ; // size of input, string + terminator
37
- defstream.next_in = (Bytef *)a; // input char array
38
- defstream.avail_out = (uInt)sizeof (b); // size of output
39
- defstream.next_out = (Bytef *)b; // output char array
35
+ defstream.avail_in =
36
+ (uInt)strlen (a) + 1 ; // size of input, string + terminator
37
+ defstream.next_in = (Bytef *)a; // input char array
38
+ defstream.avail_out = (uInt)sizeof (b); // size of output
39
+ defstream.next_out = (Bytef *)b; // output char array
40
40
41
41
// the actual compression work.
42
42
deflateInit (&defstream, Z_BEST_COMPRESSION);
@@ -47,10 +47,8 @@ int main(int argc, char* argv[])
47
47
printf (" Compressed size is: %lu\n " , strlen (b));
48
48
printf (" Compressed string is: %s\n " , b);
49
49
50
-
51
50
printf (" \n ----------\n\n " );
52
51
53
-
54
52
// STEP 2.
55
53
// inflate b into c
56
54
// zlib struct
@@ -59,10 +57,11 @@ int main(int argc, char* argv[])
59
57
infstream.zfree = Z_NULL;
60
58
infstream.opaque = Z_NULL;
61
59
// setup "b" as the input and "c" as the compressed output
62
- infstream.avail_in = (uInt)((char *)defstream.next_out - b); // size of input
63
- infstream.next_in = (Bytef *)b; // input char array
64
- infstream.avail_out = (uInt)sizeof (c); // size of output
65
- infstream.next_out = (Bytef *)c; // output char array
60
+ infstream.avail_in =
61
+ (uInt)((char *)defstream.next_out - b); // size of input
62
+ infstream.next_in = (Bytef *)b; // input char array
63
+ infstream.avail_out = (uInt)sizeof (c); // size of output
64
+ infstream.next_out = (Bytef *)c; // output char array
66
65
67
66
// the actual DE-compression work.
68
67
inflateInit (&infstream);
@@ -72,9 +71,8 @@ int main(int argc, char* argv[])
72
71
printf (" Uncompressed size is: %lu\n " , strlen (c));
73
72
printf (" Uncompressed string is: %s\n " , c);
74
73
75
-
76
74
// make sure uncompressed is exactly equal to original.
77
- assert (strcmp (a,c)== 0 );
75
+ assert (strcmp (a, c) == 0 );
78
76
79
77
return 0 ;
80
78
}
0 commit comments