In gzip library, what's the difference between 'uncompress' and 'gzopen'? - zlib

There are some functions to decompress in zlib library (zlib version 1.2.3)
I want to decompress my source zip (.gz) file using uncompress function.
It is not working (error code -3) but gzopen is. It is still not working when I input payload pointer (passing gzip header) to uncompress.
So the question is:
What's the valid arguments for uncompress function?
If it needs different format, how can I make it?

You have to use some poorly documented features of the zlib library. See my answer to this question for more information: How can I decompress a gzip stream with zlib?

Related

ffmpeg - missing avformat headers

I follow the steps here to compile FFmpeg.
And there is no problem. Its working well. But i did not understand something.
There are two folders under my home directory.
--ffmpeg_sources
--ffmpeg_build
insede of ffmpeg_sources/libavformat i have number of headers
aiff.h
apetag.h
argo_asf.h
asfcrypt.h
asf.h
ast.h
av1.h
avc.h
avformat.h
avi.h
avio.h
avio_internal.h
avlanguage.h
ogg.h
...
but ffmpeg_build/avformat has 3 header.
avformat.h
avio.h
version.h
btw this is my usr/include/x86_64-linux-gnu/libavformat
avformat.h
avio.h
version.h
Why aren't all headers in these other two files?
For ex: i want to use "ogg_read_packet" but when i try to include <libavformat/oggdec.h> i get cannot open source file "libavformat/oggdec.h"C/C++(1696) error.
Building and using the library aren't the same things.
Have a look at libavformat/oggdec.h and libavformat/oggdec.c. You should have realized, that there is no way to directly use the ogg_read_packet function.
there is no declaration in the header file
the function is declared static in the source file
If you want to encode/decode with a specific codec (here ogg), you have to find an encoder (avcodec_find_encoder or avcodec_find_encoder_by_name) or a decoder (avcodec_find_decoder or avcodec_find_decoder_by_name) and link it to a AVCodecContext via avcodec_open2.
Then for encoding use the 'encode' functions described here and for decoding the 'decode' functions described here.
For more info:
FFmpeg Documentation
FFmpeg Examples
In short, use the public Interface. Only 'God' knows the internals of FFmpeg.

Supporting multiple MIME types in a simple HTTP server

I'm programming a simple HTTP server in C. So far, my server only supports text/html. I'm trying to add more functionalities to it by supporting additional MIME types (more precisely: text /css, text/javascript, image/jpg, image/png, font/woff2). For html files, I simply used fseek() and ftell() to determine the size of the file and read(), write() to read the file into a buffer and send it to the client. Now, I have the following questions:
1.Can I treat js, css, and woff2 files the exact same as html files (figuring size, reading, and sending)?
2.For binary files (images), what differences am I expected to make? Can I still use fseek() and ftell() to determine the size? Let's say I used fread(), can I use the return value as the file length? Is fwrite() really better than write() for binary files? Do I have to encode the image file before sending (I checked the RFC but I can't find any definite answer)? Should I include the "Content-Transfer-Encoding", or is it optional?
Do I have to encode the image file before sending (I checked the RFC but I can't find any definite answer)? Should I include the "Content-Transfer-Encoding", or is it optional?
No you don't need any encoding, and, FWIW, there is no Content-Transfer-Encoding field in HTTP.

Decompressing Snappy Files Missing Stream Identifier Chunk and CRC-32C Checksum

The iWork 2013 file format includes .iwa (iWork Archive) files stored within a .zip file. "IWA files are stored in Snappy's framing format, though they do not adhere rigorously to the spec. In particular, they do not include the required Stream Identifier chunk, and compressed chunks do not include a CRC-32C checksum." https://github.com/obriensp/iWorkFileFormat/blob/master/Docs/index.md#iwa
Is there an implementation of Snappy that can decompress files missing these components? If so, is there example code?
Examples of iWork files may be found at the bottom of this page: http://fileformats.archiveteam.org/wiki/IWA. For instance, unzipping file TestReport.pages.zip shows that it contains Index.zip, which contains .iwa files.
I tried decompressing the .iwa files using the Snappy for Windows command line tool here: http://snappy.angeloflogic.com/downloads/ . However, I received the error: "Found invalid data while decoding."
I do not yet have sample code because I do not know which implementation of Snappy I should base my code on.

How to write gz file in C via zlib and compress2

I'm using zlib to write a program that compress data in several threads. so I can't use gzwrite. I'm using compress2().
*dest_len = compressBound(LOG_BUFF_SZ);
err = compress2((Bytef*)compressed_buff->buff, dest_len, (Bytef*)b->buff, size, GZ_INT_COMPRESSION_LEVEL);
write(fd, compressed_buff->buff, compressed_buff->full);
But when I try to decompress file via gzip -d I see the next output: "not in gzip format". what am I doing wrong? Thank you for your answers
compress() and compress2() compress to the zlib format, not the gzip format. You need to use the lower-level functions to be able to select the gzip format. Those are deflateInit2(), deflate() and deflateEnd(). Read the documentation in zlib.h for those functions. After that, you should also look at the heavily documented example of their use.

Using zlib with C

I am currently learning C, and am having some issues with trying to make a small program that utilizes zlib.
I have managed to compile my application (using Codeblocks/MinGW) with the zlib libraries, and compilation works fine. I have used an example based upon the zpipe.c example found over at the official zlib site (zlib.net).
On execution, the output zip file is created, but it seems malformed and/or empty. I am unable to open it using 7zip.
Here is the code that I have modified. I have simply replaced the main() function within zpipe.c.
int main() {
printf("Compression test...");
int ret;
FILE *fpsource;
FILE *fpdest;
fpsource = fopen("test.txt", "rb");
fpdest = fopen("output.zip", "wb");
ret = def(fpsource, fpdest, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK) {
printf("failure\n");
zerr(ret);
}
else {
printf("success..\n");
}
fclose(fpsource);
fclose(fpdest);
return EXIT_SUCCESS;
}
I receive no errors, and my 'success' message is printed. It's just the output file is corrupt.
zpipe.c as-is will generate the zlib format, which is raw deflate data wrapped in a zlib header and trailer. 7zip won't recognize that. It will recognize the gzip or zip format, which are entirely different wrappers on the same raw deflate data.
You can modify zpipe.c to use deflateInit2 (and inflateInit2) instead of the versions without the "2" to select the gzip format instead of the zlib format. You can read zlib.h for how to do this.
The code discussed simply compresses the file using the DEFLATE algorithm. The appropriate structures that make it a zip or gzip file are missing.

Resources