I have a concatenated file consisting of a number of archives bzip2. I also know the sizes of individual fragments bzip2in this file.
I would like to unzip the stream bzip2from a separate bzip2 data block and write the output to standard output.
First I use fseekto move the file cursor to the desired archive byte, and then read the "size" of the file's point in the call BZ2_bzRead:
int headerSize = 1234;
int firstChunkSize = 123456;
FILE *fp = fopen("pathToConcatenatedFile", "r+b");
char *bzBuf = malloc(sizeof(char) * firstChunkSize);
int bzError, bzNBuf;
BZFILE *bzFp = BZ2_bzReadOpen(&bzError, *fp, 0, 0, NULL, 0);
# move cursor past header of known size, to the first bzip2 "chunk"
fseek(*fp, headerSize, SEEK_SET);
while (bzError != BZ_STREAM_END) {
# read the first chunk of known size, decompress it
bzNBuf = BZ2_bzRead(&bzError, bzFp, bzBuf, firstChunkSize);
fprintf(stdout, bzBuf);
}
BZ2_bzReadClose(&bzError, bzFp);
free(bzBuf);
fclose(fp);
The problem is that when I compare the output of the instruction fprintfwith the output from bzip2the command line, I get two different answers.
In particular, I get less result from this code than from running bzip2on the command line.
, , , bzip2.
, bzip2 , , , C . , .
bzip2 libbzip2, - , ? .