Próbuję zaimplementować deflate zlib.h i nadmuchać funkcje, aby skompresować i rozpakować tablicę znaków (a nie plik).deflate and inflate (zlib.h) in C
Chciałbym wiedzieć, czy poniższa składnia jest poprawna? Czy brakuje czegoś lub zdefiniowałem coś niepoprawnie?
char a[50] = "Hello World!";
char b[50];
char c[50];
// deflate
// zlib struct
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = (uInt)sizeof(a); // size of input
defstream.next_in = (Bytef *)a; // input char array
defstream.avail_out = (uInt)sizeof(b); // size of output
defstream.next_out = (Bytef *)b; // output char array
deflateInit(&defstream, Z_DEFAULT_COMPRESSION);
deflate(&defstream, Z_FINISH);
deflateEnd(&defstream);
printf("Deflate:\n%lu\n%s\n", strlen(b), b);
// inflate
// zlib struct
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
infstream.avail_in = (uInt)sizeof(b); // size of input
infstream.next_in = (Bytef *)b; // input char array
infstream.avail_out = (uInt)sizeof(c); // size of output
infstream.next_out = (Bytef *)c; // output char array
inflateInit(&infstream);
inflate(&infstream, Z_NO_FLUSH);
inflateEnd(&infstream);
printf("Inflate:\n%lu\n%s\n", strlen(c), c);
Czy pytasz, ponieważ nie działa? Czy otrzymujesz komunikat o błędzie? – larsks
@larsks Kompiluje bez ostrzeżeń, ale chcę wiedzieć, czy wybrane przeze mnie funkcje i definicje mają sens, czy też powinienem używać innych. –
Rozumiem. Dziękuję za wyjaśnienie Twojego pytania. – larsks