mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-08 10:23:54 +00:00
c7355b19aa
Summary: Pull Request resolved: https://github.com/facebook/osquery/pull/5452 As suggested in another diff, this diff updates the language we use to describe the osquery licensing terms. We are changing all instances of //This source code is licensed as defined on the LICENSE file found in the root directory of this source tree.// to //This source code is licensed in accordance with the terms specified in the LICENSE file found in the root directory of this source tree.// We accomplish this with a codemod: $ codemod -md xplat/osquery/oss --extensions cpp,h,in,py,sh,mm,ps1 "(.\s+)This source code is licensed as defined on the LICENSE file found in the(.*)root directory of this source tree\." "\1This source code is licensed in accordance with the terms specified in\2the LICENSE file found in the root directory of this source tree." Reviewed By: fmanco Differential Revision: D14131290 fbshipit-source-id: 52c90da342263e2a80f5a678ecd760c19cf7513e
59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed in accordance with the terms specified in
|
|
* 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;
|
|
}
|
|
}
|