int extractToMemory(std::vector<unsigned char>& outvec, ZipEntry& info) { size_t err = UNZ_ERRNO; err = unzOpenCurrentFilePassword(m_zf, m_outer.m_password.c_str()); if (UNZ_OK != err) { std::stringstream str; str << "Error " << err << " opening internal file '" << info.name << "' in zip"; throw EXCEPTION_CLASS(str.str().c_str()); } std::vector<unsigned char> buffer; buffer.resize(WRITEBUFFERSIZE); outvec.reserve((size_t)info.uncompressedSize); do { err = unzReadCurrentFile(m_zf, buffer.data(), (unsigned int)buffer.size()); if (err < 0 || err == 0) break; outvec.insert(outvec.end(), buffer.data(), buffer.data() + err); } while (err > 0); return (int)err; }
int extractToStream(std::ostream& stream, ZipEntry& info) { size_t err = UNZ_ERRNO; err = unzOpenCurrentFilePassword(m_zf, m_outer.m_password.c_str()); if (UNZ_OK != err) { std::stringstream str; str << "Error " << err << " opening internal file '" << info.name << "' in zip"; throw EXCEPTION_CLASS(str.str().c_str()); } std::vector<char> buffer; buffer.resize(WRITEBUFFERSIZE); do { err = unzReadCurrentFile(m_zf, buffer.data(), (unsigned int)buffer.size()); if (err < 0 || err == 0) break; stream.write(buffer.data(), err); if (!stream.good()) { err = UNZ_ERRNO; break; } } while (err > 0); stream.flush(); return (int)err; }
#else #define DEBUG_LOG(str, ...) fprintf(stderr, str, ## __VA_ARGS__) #endif #ifndef __has_builtin #define __has_builtin(x) 0 #endif #if !__has_builtin(__builtin_unreachable) #define __builtin_unreachable abort #endif /** * Class of exceptions to distinguish between this and other exception types. */ static const uint64_t objc_exception_class = EXCEPTION_CLASS('G','N','U','C','O','B','J','C'); static const uint64_t cxx_exception_class = EXCEPTION_CLASS('G','N','U','C','C','+','+','\0'); /** * Structure used as a header on thrown exceptions. */ struct objc_exception { /** The selector value to be returned when installing the catch handler. * Used at the call site to determine which catch() block should execute. * This is found in phase 1 of unwinding then installed in phase 2.*/ int handlerSwitchValue; /** The cached landing pad for the catch handler.*/ void *landingPad; /** * Next pointer for chained exceptions.