MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / addFile

Method addFile

src/utilities/core/ZipFile.cpp:24–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24void ZipFile::addFile(const openstudio::path& localPath, const openstudio::path& destinationPath) {
25 if (zipOpenNewFileInZip(m_zipFile, openstudio::toString(destinationPath).c_str(), nullptr, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED,
26 Z_DEFAULT_COMPRESSION)
27 != ZIP_OK) {
28 throw std::runtime_error("Unable to create new file in archive: " + openstudio::toString(destinationPath));
29 }
30
31 try {
32 std::ifstream ifs(openstudio::toSystemFilename(localPath), std::ios_base::in | std::ios_base::binary);
33
34 if (!ifs.is_open() || ifs.fail()) {
35 throw std::runtime_error("Unable to open local file: " + openstudio::toString(localPath));
36 }
37
38 while (!ifs.eof()) {
39 std::vector<char> buffer(1024);
40 ifs.read(&buffer.front(), buffer.size());
41 std::streamsize bytesread = ifs.gcount();
42
43 if (ifs.fail() && !ifs.eof()) {
44 throw std::runtime_error("Error reading from local file: " + openstudio::toString(localPath));
45 }
46
47 zipWriteInFileInZip(m_zipFile, &buffer.front(), static_cast<unsigned int>(bytesread));
48 }
49 } catch (...) {
50 zipCloseFileInZip(m_zipFile);
51 throw;
52 }
53
54 zipCloseFileInZip(m_zipFile);
55}
56
57void ZipFile::addDirectory(const openstudio::path& localDir, const openstudio::path& destinationDir) {
58 // following conventions in openstudio::copyDirectory

Callers 1

TEST_FFunction · 0.45

Calls 5

toSystemFilenameFunction · 0.85
eofMethod · 0.80
toStringFunction · 0.70
readMethod · 0.45
sizeMethod · 0.45

Tested by 1

TEST_FFunction · 0.36