static bool httprequest_gzip_decompress(const void* pInDate, size_t nSize, std::string& raw_data) { z_stream zs ; memset(&zs,0,sizeof(zs)); std::vector<Byte> temp_buf (8 * 1024) ; bool bRet = false ; int nErr = inflateInit2 (&zs, 47) ; if (nErr == Z_OK) { zs.next_in = (Byte*)const_cast<void*>(pInDate) ; zs.avail_in = (unsigned int)nSize ; for (;;) { zs.avail_out = (unsigned int)temp_buf.size() ; zs.next_out = &temp_buf[0] ; nErr = inflate (&zs, Z_NO_FLUSH) ; size_t nWrite = zs.total_out - raw_data.size() ; if (nWrite) { raw_data.append ((char*)&temp_buf[0], nWrite) ; } if (nErr == Z_STREAM_END) { bRet = true ; break; } else if (nErr == Z_OK) // continue { } else { break; } } inflateEnd (&zs) ; } // assert(bRet) ; return bRet ; }
uint32_t AudioSourceOJM::Read(short* buffer, size_t count) { std::vector<short> temp_buf(count); size_t read = 0; if (TemporaryState.Enabled == 0) return 0; if (TemporaryState.Enabled == OJM_WAV) { read = sf_read_short(static_cast<SNDFILE*>(TemporaryState.File), temp_buf.data(), count); CheckInterruption(); } else if (TemporaryState.Enabled == OJM_OGG) { auto size = count * sizeof(short); while (read < size) { int sect; int res = ov_read(static_cast<OggVorbis_File*>(TemporaryState.File), reinterpret_cast<char*>(temp_buf.data()) + read, size - read, 0, 2, 1, §); if (res > 0) read += res; if (res <= 0) { if (res < 0) Log::Printf("Error loading ogg (%d)\n", res); break; } CheckInterruption(); } if (read < size) Log::Printf("AudioSourceOJM: PCM count differs from what's reported! (%d out of %d)\n", read, size); } std::copy(temp_buf.begin(), temp_buf.end(), buffer); return read; // We /KNOW/ we won't be overreading. }
void utf8print(const char* str) { #if PLATFORM == PLATFORM_WINDOWS std::wstring wtemp_buf; std::string temp_buf(str); if (!Utf8toWStr(temp_buf, wtemp_buf, 6000)) return; // Guarantee null termination if (!temp_buf.empty()) { wtemp_buf.push_back('\0'); temp_buf.resize(wtemp_buf.size()); CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], wtemp_buf.size()); } printf("%s", temp_buf.c_str()); #else printf("%s", str); #endif }