16 #define WIN32_LEAN_AND_MEAN
36 void* inData,
size_t inDataSize, std::vector<unsigned char>& outData)
41 unsigned long resSize;
43 outData.resize(inDataSize + inDataSize / 1000 + 50);
44 resSize = (
unsigned long)outData.size();
46 &outData[0], &resSize, (
unsigned char*)inData,
47 (
unsigned long)inDataSize);
50 outData.resize(resSize);
59 const std::vector<unsigned char>& inData,
60 std::vector<unsigned char>& outData)
65 unsigned long resSize;
67 outData.resize(inData.size() + inData.size() / 1000 + 50);
68 resSize = (
unsigned long)outData.size();
70 &outData[0], &resSize, &inData[0], (
unsigned long)inData.size());
73 outData.resize(resSize);
86 unsigned long resSize;
87 std::vector<unsigned char> outData;
89 outData.resize(inDataSize + inDataSize / 1000 + 50);
90 resSize = (
unsigned long)outData.size();
93 &outData[0], &resSize, (
unsigned char*)inData,
94 (
unsigned long)inDataSize);
97 outData.resize(resSize);
100 out.
Write(&outData[0], resSize);
109 const std::vector<unsigned char>& inData,
CStream& out)
114 unsigned long resSize;
115 std::vector<unsigned char> outData;
116 outData.resize(inData.size() + inData.size() / 1000 + 50);
117 resSize = (
unsigned long)outData.size();
120 &outData[0], &resSize, &inData[0], (
unsigned long)inData.size());
124 outData.resize(resSize);
127 out.
Write(&outData[0], resSize);
136 void* inData,
size_t inDataSize, std::vector<unsigned char>& outData,
137 size_t outDataEstimatedSize)
142 outData.resize(outDataEstimatedSize);
143 unsigned long actualOutSize;
146 &outData[0], &actualOutSize, (
unsigned char*)inData,
147 (
unsigned long)inDataSize);
151 outData.resize(actualOutSize);
160 void* inData,
size_t inDataSize,
void* outData,
size_t outDataBufferSize,
161 size_t& outDataActualSize)
166 unsigned long actualOutSize = (
unsigned long)outDataBufferSize;
169 (
unsigned char*)outData, &actualOutSize, (
unsigned char*)inData,
170 (
unsigned long)inDataSize);
174 outDataActualSize = actualOutSize;
183 CStream& inStream,
size_t inDataSize,
void* outData,
184 size_t outDataBufferSize,
size_t& outDataActualSize)
189 unsigned long actualOutSize = (
unsigned long)outDataBufferSize;
190 std::vector<unsigned char> inData;
192 inData.resize(inDataSize);
193 inStream.
Read(&inData[0], inDataSize);
196 (
unsigned char*)outData, &actualOutSize, &inData[0],
197 (
unsigned long)inDataSize);
201 outDataActualSize = actualOutSize;
217 const int bytes2read = 1 << 20;
219 size_t total_bytes = 0;
226 act_read = iss.
Read(&
buffer[total_bytes], bytes2read);
227 total_bytes += act_read;
228 }
while (act_read == bytes2read);
230 buffer.resize(total_bytes);
236 const int compress_level)
239 oss.
open(file_path, compress_level);
261 const std::vector<uint8_t>& in_data, std::vector<uint8_t>& out_gz_data,
262 const int compress_level)
265 if (in_data.empty())
return true;
267 const unsigned int nPipeName =
275 format(
"\\\\.\\pipe\\mrpt_compress_gz_data_block_%u", nPipeName);
277 HANDLE hPipe = CreateNamedPipeA(
278 pipe_file_name.c_str(),
279 PIPE_ACCESS_DUPLEX | 0x00080000 ,
280 PIPE_TYPE_BYTE, PIPE_UNLIMITED_INSTANCES, in_data.size() + 1000,
281 in_data.size() + 1000, 0,
nullptr);
282 if (hPipe == INVALID_HANDLE_VALUE)
286 pipe_file_name =
format(
"/tmp/mrpt_compress_gz_data_block_%u", nPipeName);
295 pipe_file_name.c_str(),
format(
"wb%i", compress_level).c_str());
298 retVal = (int)in_data.size() ==
299 gzwrite(f, &in_data[0], in_data.size());
304 std::cerr <<
"[compress_gz_data_block] Error writing to pipe: "
305 << pipe_file_name << std::endl;
313 const size_t N = GetFileSize(hPipe,
nullptr);
316 out_gz_data.resize(N);
318 SetFilePointer(hPipe, 0,
nullptr, FILE_BEGIN);
321 ReadFile(hPipe, &out_gz_data[0], N, &nRead,
nullptr);
333 if (iss.
open(pipe_file_name))
336 out_gz_data.resize(M);
337 if (M) retVal = M == iss.
Read(&out_gz_data[0], M);
352 remove(pipe_file_name.c_str());
359 const std::vector<uint8_t>& in_gz_data, std::vector<uint8_t>& out_data)
362 if (in_gz_data.empty())
return true;
369 remove(tmp_file_name.c_str());