当前位置: 首页>>代码示例>>C++>>正文


C++ zip函数代码示例

本文整理汇总了C++中zip函数的典型用法代码示例。如果您正苦于以下问题:C++ zip函数的具体用法?C++ zip怎么用?C++ zip使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QLatin1String

void KArchiveTest::testZipAddLocalDirectory()
{
    // Prepare local dir
    KTempDir tmpDir;
    const QString dirName = tmpDir.name();

    const QByteArray file1Data = "Hello Shantanu";
    const QString file1 = QLatin1String("file1");
    QVERIFY(writeFile(dirName, file1, file1Data));

    {
        KZip zip(s_zipFileName);

        QVERIFY(zip.open(QIODevice::WriteOnly));
        QVERIFY(zip.addLocalDirectory(dirName, "."));
        QVERIFY(zip.close());
    }
    {
        KZip zip(s_zipFileName);

        QVERIFY(zip.open(QIODevice::ReadOnly));

        const KArchiveDirectory* dir = zip.directory();
        QVERIFY(dir != 0);

        const KArchiveEntry* e = dir->entry(file1);
        QVERIFY(e && e->isFile());
        const KArchiveFile* f = (KArchiveFile*)e;
        QCOMPARE(f->data(), file1Data);
    }
}
开发者ID:vasi,项目名称:kdelibs,代码行数:31,代码来源:karchivetest.cpp

示例2: settings

void FormulaDialog::accept()
{
    extern Calculator calculator;
    QString formula = ui.formulaComboBox->currentText();
    if (calculator.setFormula(formula)) {
        QDialog::accept();
        EigenbroetlerWindow *eb = EigenbroetlerWindow::instance();
        QSettings settings(eb->app_owner, eb->app_name);
        settings.setValue(sq_name, ui.squareCheckBox->checkState() ? true : false);
        settings.setValue(dim_name, ui.twoDRadioButton->isChecked());
        settings.setValue(width_name, ui.widthSpinBox->value());
        settings.setValue(height_name, ui.heightSpinBox->value());

        settings.setValue(start_name, ui.firstNSpinBox->value());
        settings.setValue(stop_name, ui.finalNSpinBox->value());
        settings.setValue(incr_name, ui.incrNSpinBox->value());
        settings.setValue(multi_name, ui.multiviewCheckBox->checkState() ? true : false);

        std::map<QString, QString> frms;
        frms[zip(formula)] = formula;
        int item = 0;
        settings.setValue(form_name.arg(item++), formula);
        for (int i = 0; i < num_formulae && i < ui.formulaComboBox->count(); ++i) {
            QString const key = zip(ui.formulaComboBox->itemText(i));
            if (frms.find(key) == frms.end()) {
                frms[key] = ui.formulaComboBox->itemText(i);
                settings.setValue(form_name.arg(item++), ui.formulaComboBox->itemText(i));
            }
        }
    }
}
开发者ID:magister-ludi,项目名称:eigenbroetler,代码行数:31,代码来源:formula_dialog.cpp

示例3: result

Foam::tmp<Foam::vectorField> Foam::waveSuperposition::velocity
(
    const scalar t,
    const vectorField& xyz
) const
{
    vectorField result(xyz.size(), vector::zero);

    forAll(waveModels_, wavei)
    {
        const vector2D d(cos(waveAngles_[wavei]), sin(waveAngles_[wavei]));
        const vector2DField xz
        (
            zip
            (
                d & zip(xyz.component(0), xyz.component(1)),
                tmp<scalarField>(xyz.component(2))
            )
        );
        const vector2DField uw
        (
            waveModels_[wavei].velocity(t, xz)
        );
        result += zip
        (
            d.x()*uw.component(0),
            d.y()*uw.component(0),
            uw.component(1)
        );
    }

    tmp<scalarField> s = scale(zip(xyz.component(0), xyz.component(1)));

    return s*result;
}
开发者ID:OpenFOAM,项目名称:OpenFOAM-dev,代码行数:35,代码来源:waveSuperposition.C

示例4: main

int main(){

int a[] = {1,7,9,4};
int b[] = {4,5,6,9};
int sizenuova = 100;
int testpari[sizenuova];
int testdispari[sizenuova];

int lunghezza1,lunghezza2;
int ris1;

lunghezza1 = sizeof(a)/sizeof(int);
lunghezza2 = sizeof(b)/sizeof(int);

int size = lunghezza1 *2;
int c[size];

if(lunghezza1!=lunghezza2){

return EXIT_FAILURE;

	}
int j = 0;

for(int i = 0; i < (sizenuova*2); i++){
	if(i % 2 == 0){
	testpari[j] = i;
	j++;
	}
}

j = 0;

for(int i = 0; i < (sizenuova*2); i++){
	if(i % 2 != 0){
	testdispari[j] = i;
	j++;
	}
}

zip(testpari,testdispari,c,sizenuova*+1);

zip(a,b,c,lunghezza1);

ris1 = somma(c,size);

printf("La somma è: %d\n", ris1);

return EXIT_SUCCESS;
} 
开发者ID:corsoiot,项目名称:IRES2016_langc,代码行数:50,代码来源:Esercizio4.c

示例5: throw

void Resources::load_resources(bool home_paks_only) throw (ResourcesException) {
    try {
        if (!home_paks_only) {
            /* scan main directories */
            subsystem << "scanning main directories" << std::endl;
            read_all(resource_directory + dir_separator, 0, true);

            /* read main paks */
            Directory dir(resource_directory, ".pak");
            const char *entry = 0;
            while ((entry = dir.get_entry())) {
                subsystem << "scanning " << entry << ".pak" << std::endl;
                try {
                    ZipReader zip(resource_directory + dir_separator + entry + ".pak");
                    read_all("", &zip, true);
                    loaded_paks.push_back(LoadedPak(zip.get_zip_filename(), zip.get_zip_short_filename(), zip.get_hash(), false));
                } catch (const ZipException& e) {
                    subsystem << e.what() << std::endl;
                }
            }
        }

        /* scan user directories */
        subsystem << "scanning user directories" << std::endl;
        read_all(get_home_directory() + dir_separator + UserDirectory + dir_separator, 0, false);

        /* read home directory */
        std::string hdir = get_home_directory() + dir_separator + UserDirectory;
        Directory dir(hdir, ".pak");
        const char *entry = 0;
        while ((entry = dir.get_entry())) {
            subsystem << "scanning " << entry << ".pak" << std::endl;
            try {
                ZipReader zip(hdir + dir_separator + entry + ".pak");
                read_all("", &zip, false);
                loaded_paks.push_back(LoadedPak(zip.get_zip_filename(), zip.get_zip_short_filename(), zip.get_hash(), true));
            } catch (const ZipException& e) {
                subsystem << e.what() << std::endl;
            }
        }

        /* prepare all resources for quick accesses */
        subsystem.set_scanlines_icon(get_icon("scanlines"));
        prepare_resources();
    } catch (const Exception& e) {
        destroy_resources(false);
        throw ResourcesException(e.what());
    }
}
开发者ID:SuperNascher,项目名称:goatattack,代码行数:49,代码来源:Resources.cpp

示例6: GGI_vnc_zlib

int
GGI_vnc_zlib(ggi_vnc_client *client, ggi_rect *update)
{
	struct zlib_ctx_t *ctx = client->zlib_ctx;
	ggi_vnc_buf tmp_buf;

	/* fake it for the raw encoder so that it renders the update
	 * in an intermediate buffer
	 */
	tmp_buf = client->wbuf;
	client->wbuf = ctx->wbuf;
	client->wbuf.pos = client->wbuf.size = 0;

	GGI_vnc_raw(client, update);

	/* swap the buffers back */
	ctx->wbuf = client->wbuf;
	client->wbuf = tmp_buf;

	/* change header to Zlib encoding */
	ctx->wbuf.buf[11] = 6; /* Zlib */

	/* copy the revised header to the real buffer */
	GGI_vnc_buf_reserve(&client->wbuf, client->wbuf.size + 16);
	memcpy(&client->wbuf.buf[client->wbuf.size], ctx->wbuf.buf, 12);

	client->wbuf.size += 12;

	/* zip up the intermediate buffer */
	zip(client, &ctx->wbuf.buf[12], ctx->wbuf.size - 12);
	return 1;
}
开发者ID:antrik,项目名称:libggi,代码行数:32,代码来源:zlib.c

示例7: doSave

static int doSave(const QString &fileName)
{
    KZip zip(fileName);
    if (!zip.open(QIODevice::WriteOnly)) {
        qWarning() << "Could not open" << fileName << "for writing";
        return 1;
    }

    const QByteArray data = "This is the data for the main file";
    bool writeOk = zip.writeFile(QStringLiteral("maindoc.txt"), data);
    if (!writeOk) {
        qWarning() << "Write error (main file)";
        return 1;
    }
    const QByteArray data2 = "This is the data for the other file";
    writeOk = zip.writeFile(QStringLiteral("subdir/other.txt"), data2);
    if (!writeOk) {
        qWarning() << "Write error (other file)";
        return 1;
    }
    //writeOk = zip.addLocalFile("David.jpg", "picture.jpg");
    //if (!writeOk) {
    //    qWarning() << "Write error (picture)";
    //    return 1;
    //}
    return 0;
}
开发者ID:barcelonascience,项目名称:karchive,代码行数:27,代码来源:kziptest.cpp

示例8: fn

void GEUIDialog::SaveViewAsKmz( wxString filename, wxString viewname ) 
{
      //TODO: - kml, jpg, zip it
      wxFileName fn(filename);
      wxFFileOutputStream out(filename);
      wxZipOutputStream zip(out);
      double west, east, north, south, lat, lon, alt;
      bool proj, exa;

      GEGetPointOnTerrain(GE_SCR_UPCENTER, north, lon, alt, proj, exa);
      GEGetPointOnTerrain(GE_SCR_LOWCENTER, south, lon, alt, proj, exa);
      GEGetPointOnTerrain(GE_SCR_LEFTCENTER, lat, west, alt, proj, exa);
      GEGetPointOnTerrain(GE_SCR_RIGHTCENTER, lat, east, alt, proj, exa);

      wxString tempimg = wxFileName::CreateTempFileName(_T("gecomapi"));
      SaveViewAsJPG(tempimg);
      zip.PutNextEntry(wxString::Format(_T("files/%s.jpg"), fn.GetName()));
      wxFileInputStream stream(tempimg);
	zip.Write(stream);
      zip.PutNextEntry(_T("doc.kml"));
      wxCharBuffer buffer;
      buffer = wxConvertWX2MB(wxString::Format(_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><GroundOverlay><name>%s</name><Icon><href>files/%s.jpg</href><drawOrder>0</drawOrder></Icon><LatLonBox><north>%f</north><south>%f</south><east>%f</east><west>%f</west><rotation>%f</rotation></LatLonBox></GroundOverlay></kml>"), encodeXMLEntities(viewname), fn.GetName(), north, south, east, west, 0.0));
      zip.Write(buffer.data(), strlen(buffer.data()));
      wxRemoveFile(tempimg);
}
开发者ID:nohal,项目名称:gecomapi_pi,代码行数:25,代码来源:gecomapi.cpp

示例9: brokenZip

void KArchiveTest::testReadZipError()
{
    QFile brokenZip(QStringLiteral("broken.zip"));
    QVERIFY(brokenZip.open(QIODevice::WriteOnly));

    // incomplete magic
    brokenZip.write(QByteArray("PK\003"));

    brokenZip.close();
    {
        KZip zip(QStringLiteral("broken.zip"));

        QVERIFY(!zip.open(QIODevice::ReadOnly));
        QCOMPARE(
            zip.errorString(),
            tr("Invalid ZIP file. Unexpected end of file. (Error code: %1)").arg(1));

        QVERIFY(brokenZip.open(QIODevice::WriteOnly | QIODevice::Append));

        // add rest of magic, but still incomplete header
        brokenZip.write(QByteArray("\004\000\000\000\000"));

        brokenZip.close();

        QVERIFY(!zip.open(QIODevice::ReadOnly));
        QCOMPARE(
            zip.errorString(),
            tr("Invalid ZIP file. Unexpected end of file. (Error code: %1)").arg(4));
    }

    QVERIFY(brokenZip.remove());
}
开发者ID:barcelonascience,项目名称:karchive,代码行数:32,代码来源:karchivetest.cpp

示例10: zip

/**
 * @brief Exports the portfolios to the archive.
 * The portfolios must have been sets before with addPortfolios.
 */
void ExportManager::exportArchive() {
	QuaZip zip(this->archivePath);
	if(!zip.open(QuaZip::mdCreate)) {
		throw ExportException("Cannot create archive "+this->archivePath+".");
	}

	QuaZipFile archivedFile(&zip);

	// Adds the descriptor file in the archive:
	QByteArray data = writeDescriptor();
	if(!archivedFile.open(QIODevice::WriteOnly, QuaZipNewInfo("portfolios.json"))) {
		throw ExportException("Cannot create descriptor file in archive.");
	}
	archivedFile.write(data);
	archivedFile.close();

	// Adds the reports and assets' files to the archive:
	QDir resourcesFolder(SQLiteManager::getSessionFolder() + QDir::separator() + "Resources");
	addToArchive(resourcesFolder, "Reports", archivedFile);
	addToArchive(resourcesFolder, "Assets", archivedFile);

	zip.close();
	if(zip.getZipError() != 0) {
		throw ExportException("Error while archiving ("+QString::number(zip.getZipError())+").");
	}
}
开发者ID:YunhaiZhou,项目名称:VaRSoft,代码行数:30,代码来源:ExportManager.cpp

示例11: zip

void KArchiveTest::testZipMaxLength()
{
    KZip zip( s_zipMaxLengthFileName );

    QVERIFY( zip.open( QIODevice::WriteOnly ) );

    // Similar to testTarMaxLength just to make sure, but of course zip doesn't have
    // those limitations in the first place.
    for (int i = 98; i < 514 ; i++ )
    {
      QString str, num;
      str.fill( 'a', i-10 );
      num.setNum( i );
      num = num.rightJustified( 10, '0' );
      zip.writeFile( str+num, "testu", "testg", "hum", 3 );
    }
    QVERIFY( zip.close() );

    QVERIFY( zip.open( QIODevice::ReadOnly ) );

    const KArchiveDirectory* dir = zip.directory();
    QVERIFY( dir != 0 );
    const QStringList listing = recursiveListEntries( dir, "", 0 );

    QCOMPARE( listing[  0], QString("mode=100644 path=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000098 type=file size=3") );
    QCOMPARE( listing[  3], QString("mode=100644 path=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000101 type=file size=3") );
    QCOMPARE( listing[  4], QString("mode=100644 path=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000102 type=file size=3") );

    QCOMPARE( listing.count(), 514 - 98 );

    QVERIFY( zip.close() );
}
开发者ID:vasi,项目名称:kdelibs,代码行数:32,代码来源:karchivetest.cpp

示例12: jsonFile

void
FileStore::compressRide(RideFile*ride, QByteArray &data, QString name)
{
    // compress via a temporary file
    QTemporaryFile tempfile;
    tempfile.open();
    tempfile.close();

    // write as json
    QFile jsonFile(tempfile.fileName());
    if (RideFileFactory::instance().writeRideFile(NULL, ride, jsonFile, "json") == true) {

        // create a temp zip file
        QTemporaryFile zipFile;
        zipFile.open();
        zipFile.close();

        // add files using zip writer
        QString zipname = zipFile.fileName();
        ZipWriter writer(zipname);

        // read the ride file back and add to zip file
        jsonFile.open(QFile::ReadOnly);
        writer.addFile(name, jsonFile.readAll());
        jsonFile.close();
        writer.close();

        // now read in the zipfile
        QFile zip(zipname);
        zip.open(QFile::ReadOnly);
        data = zip.readAll();
        zip.close();
    }
}
开发者ID:jto2000,项目名称:GoldenCheetah,代码行数:34,代码来源:FileStore.cpp

示例13: Unzip

 /// @brief Replaces good byte(s) with bad one(s), then implements ZIP
 /// @return False on failure
 bool Unzip() {
   std::vector<unsigned char> bad_bytes = good_bytes;
   std::fill_n(bad_bytes.begin() + offset, amount, byte);
   std::string str(bad_bytes.begin(), bad_bytes.end());
   i2p::util::ZIP zip(str, str.size());
   return zip.Unzip();
 }
开发者ID:SpaceAdventure,项目名称:kovri,代码行数:9,代码来源:ZIP.cpp

示例14: zip

/**OK
 * Comprime il file fileName nel file fileCompressed.
 * Se la funzione fallisce restituisce false e cancella il file che si e tentato
 * di creare.
 *
 * La funzione fallisce se:
 * * non si riesce ad aprire l'oggetto zip;
 * * la compressione del file fallisce;
 * * non si riesce a chiudere l'oggetto zip;
 */
bool JlCompress::compressFile(QString fileCompressed, QString file)
{
    // Creo lo zip
    QuaZip zip(fileCompressed);
    QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
    if(!zip.open(QuaZip::mdCreate))
    {
        QFile::remove(fileCompressed);
        return false;
    }

    // Aggiungo il file
    if(!compressFile(&zip, file, QFileInfo(file).fileName()))
    {
        QFile::remove(fileCompressed);
        return false;
    }

    // Chiudo il file zip
    zip.close();
    if(zip.getZipError() != 0)
    {
        QFile::remove(fileCompressed);
        return false;
    }

    return true;
}
开发者ID:Kojirion,项目名称:ChessX,代码行数:38,代码来源:JlCompress.cpp

示例15: QFETCH

void TestQuaZipDir::entryList()
{
    QFETCH(QString, zipName);
    QFETCH(QStringList, fileNames);
    QFETCH(QString, dirName);
    QFETCH(int, filter);
    QFETCH(int, sort);
    QDir::Filters filters = static_cast<QDir::Filters>(filter);
    QDir::SortFlags sorting = static_cast<QDir::SortFlags>(sort);
    QFETCH(QStringList, entries);
    QDir curDir;
    if (!createTestFiles(fileNames)) {
        QFAIL("Couldn't create test files");
    }
    if (!createTestArchive(zipName, fileNames)) {
        QFAIL("Couldn't create test archive");
    }
    removeTestFiles(fileNames);
    QuaZip zip(zipName);
    QVERIFY(zip.open(QuaZip::mdUnzip));
    QuaZipDir dir(&zip, dirName);
    QCOMPARE(dir.entryList(filters, sorting), entries);
    zip.close();
    curDir.remove(zipName);
}
开发者ID:ASGAlex,项目名称:openpsy,代码行数:25,代码来源:testquazipdir.cpp


注:本文中的zip函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。