Почему gzip не до конца распаковывает мой архив?

Пытаюсь программно распаковать сдвоенный архив cpio.gz:

#include <stdio.h>
#include <archive.h>
#include <archive_entry.h>
#include <zlib.h>
#include <sys/stat.h>
#include <stdlib.h>

int main() {
    struct stat buf;
    stat("archive.cpio.gz", &buf);
    const unsigned int sizearch = buf.st_size;
    char *gzbuf = new char[sizearch];
    gzFile pzfile = gzopen("archive.cpio.gz", "rb");
    gzread(pzfile, gzbuf, sizearch);
    gzclose(pzfile);
    printf("%s\n\n", gzbuf); // debugging GZIP
    struct archive *a;
    struct archive_entry *entry;
    int r;
    a = archive_read_new();
    archive_read_support_filter_all(a);
    archive_read_support_format_all(a);
    archive_read_support_format_raw(a);
    r = archive_read_open_memory(a, gzbuf, sizearch);
    if (r != ARCHIVE_OK) {
        delete[] gzbuf;
        fprintf(stderr, "Error read of archive!\n");
        exit(1);
    }
    while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
        printf("%s\n",archive_entry_pathname(entry));
    }
    r = archive_read_free(a);
    delete[] gzbuf;
    if (r != ARCHIVE_OK) {
        fprintf(stderr, "Error read of archive!\n");
        exit(1);
    }
    return 0;
}

Компилирую, запускаю:

 ~ # g++ extract.cpp -larchive -lz -o extract_cpio_gz
 ~ # ./extract_cpio_gz
070701003C0E8C000081800000000000000000000000016293A86500000007000001030000002600000000000000000000000A00000000test2.txt

test2.txt
 ~ # cat archive.cpio.gz | gzip -kdc
070701003C0E8C000081800000000000000000000000016293A86500000007000001030000002600000000000000000000000A00000000test2.txtHello!
070701003C0E84000081800000000000000000000000016293A4F00000001B000001030000002600000000000000000000000900000000test.txtIt works!
It really works!
07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!

И что мне делать? Почему GZIP не до конца распаковывает архив?

UPD: Есть догадка, что проблема в нулевом байте после имени файла test2.txt... Хм, предлагается побайтово расжать файл? А как?


Ответы (0 шт):