osquery-1/osquery/remote/requests.cpp
Filipe Manco a67525fae1 Fix LICENSE information on file headers (#5375)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5375

LICENSE is now defined in a single file on the root of the project, update the
header to contain that information.

**Project LICENSE did not change.**

Reviewed By: akindyakov

Differential Revision: D13750575

fbshipit-source-id: 1e608a81b260b8395f9d008fc67f463160c1fc2b
2019-01-21 11:51:54 -08:00

59 lines
1.2 KiB
C++

/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed as defined on the LICENSE file found in the
* root directory of this source tree.
*/
#include <cstring>
#include <string>
#include <zlib.h>
namespace osquery {
#define MOD_GZIP_ZLIB_WINDOWSIZE 15
#define MOD_GZIP_ZLIB_CFACTOR 9
std::string compressString(const std::string& data) {
z_stream zs;
memset(&zs, 0, sizeof(zs));
if (deflateInit2(&zs,
Z_BEST_COMPRESSION,
Z_DEFLATED,
MOD_GZIP_ZLIB_WINDOWSIZE + 16,
MOD_GZIP_ZLIB_CFACTOR,
Z_DEFAULT_STRATEGY) != Z_OK) {
return std::string();
}
zs.next_in = (Bytef*)data.data();
zs.avail_in = static_cast<uInt>(data.size());
int ret = Z_OK;
std::string output;
{
char buffer[16384] = {0};
while (ret == Z_OK) {
zs.next_out = reinterpret_cast<Bytef*>(buffer);
zs.avail_out = sizeof(buffer);
ret = deflate(&zs, Z_FINISH);
if (output.size() < zs.total_out) {
output.append(buffer, zs.total_out - output.size());
}
}
}
deflateEnd(&zs);
if (ret != Z_STREAM_END) {
return std::string();
}
return output;
}
}