Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The archive module

Archives: tar files, read entry by entry, extracted safely into a directory, or written.

Bring it in with import archive. Combine it with compress for .tar.gz: wrap the file in a compress.DecompressReader to read one, or in a compress.CompressWriter to write one. A damaged archive is an io.IoError whose is_invalid_input() holds.

Example

import archive;
import io;

main(): int {
    var out = io.ByteWriter();
    var writer = archive.TarWriter(out);
    writer.append_file("hello.txt", "hi\n".bytes());
    writer.finish();

    var reader = archive.TarReader(io.ByteReader(out.bytes));
    var entry = reader.next_entry().value().value();
    assert(entry.path == "hello.txt" && entry.size == 3, "the header");
    assert(reader.read_all().value() == "hi\n".bytes(), "the contents");
    return 0;
}

Source: runtime/archive/module.pep