Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module main;
- import std.stdio;
- import std.string;
- import std.conv;
- import std.file;
- import std.c.stdlib;
- import libarchive.all;
- void main(string[] args)
- {
- if (args.length < 2)
- {
- writefln("Usage:\n%s filename.tar", args[0]);
- return;
- }
- string filename = args[1];
- archive* a = archive_read_new();
- archive_read_support_format_tar(a);
- int r = archive_read_open_filename(a, cast(char*)toStringz(filename), 10240);
- archive_entry* entry;
- while (archive_read_next_header(a, &entry) == ARCHIVE_OK)
- {
- char* n = archive_entry_pathname(entry);
- string path = to!string(n);
- if (archive_entry_filetype(entry) == AE_IFDIR)
- {
- if (!exists(path))
- mkdir(path);
- }
- else
- {
- size_t size = cast(size_t)archive_entry_size(entry);
- if (size > 0)
- {
- void* fileContents = malloc(size);
- archive_read_data_into_buffer(a, fileContents, size);
- std.file.write(path, fileContents[0..size]);
- free(fileContents);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement