Skip to content

Instantly share code, notes, and snippets.

@dholth
Created April 29, 2022 12:42
Show Gist options
  • Save dholth/4c9d7cd6f31147bfadcce906a8b799c3 to your computer and use it in GitHub Desktop.
Save dholth/4c9d7cd6f31147bfadcce906a8b799c3 to your computer and use it in GitHub Desktop.
extract .zst-compressed plain text with libarchive
#include <archive.h>
#include <stdio.h>
int main(int argc, char **argv) {
struct archive *a;
struct archive_entry *ae;
char buffer[10240];
int rc;
a = archive_read_new();
rc = archive_read_support_filter_zstd(a);
printf("filter %d\n", rc);
printf("%s %d", archive_error_string(a), archive_errno(a));
rc = archive_read_support_format_raw(a);
printf("format raw %d\n", rc);
printf("%s %d", archive_error_string(a), archive_errno(a));
rc = archive_read_open_filename(a, "setup.py.zst", 10240);
printf("open %d\n", rc);
printf("%s %d", archive_error_string(a), archive_errno(a));
rc = archive_read_next_header(a, &ae);
printf("read header %d\n", rc);
printf("%s %d", archive_error_string(a), archive_errno(a));
rc = archive_read_data(a, buffer, 10240);
printf("read %d\n", rc);
printf("%s %d", archive_error_string(a), archive_errno(a));
printf("buffer %s\n", buffer);
archive_free(a);
printf("%s %d", archive_error_string(a), archive_errno(a));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment