Beispiel #1
0
int AppTar::run(int argc, char **argv)
{
    _options.parse(argc, argv);

    if (_options.create())
        return _createArchive();

    FILE *fp = fopen(_options.archive().c_str(), "r");

    if (fp == 0)
        throw "No such file or directory";

    BitInputFile bif;
    BitInput2File bif2;
    streambuf *bt;
    istream *is;
    TarStream *ts;
    
    switch (_options.compression())
    {
    case 3:
        bif.open(fp);
        bt = new DecStreamBuf(&bif);
        break;
    case 2:
        bif2.open(fp);
        bt = new GzipStreamBuf(&bif2);
        break;
    default:
        bt = new buftest(fp);
    }

    is = new istream(bt);
    ts = new TarStream(is);
    
    if (_options.table())
        ts->list(_options.verbose());

    if (_options.extract())
        ts->extract(_options.verbose());

    delete ts;
    delete is;
    delete bt;
    fclose(fp);
    return 0;
}
Beispiel #2
0
int AppTar::_createArchive()
{
    TarWriter t;
    ofstream ofs(_options.archive().c_str());
    ifstream ifs("yes.cpp");
    //ofs << "Onzin\n";
    SHeader sh = {};
    strcpy(sh.name, "yes.cpp");
    strcpy(sh.mode, "0000644");
    strcpy(sh.uid, "0001750");
    strcpy(sh.gid, "0001750");
    strcpy(sh.size, "00000000450");
    strcpy(sh.mtime, "12345678123");
    strcpy(sh.chksum, "000000");
    sh.typeflag = 1;
    t.writeFile(ofs, ifs, sh);
    ifs.close();
    ofs.close();
    return 0;
}