15 #ifdef MRPT_OS_WINDOWS 16 #define WIN32_LEAN_AND_MEAN 37 void* inData,
size_t inDataSize, std::vector<unsigned char>& outData)
42 unsigned long resSize;
44 outData.resize(inDataSize + inDataSize / 1000 + 50);
45 resSize = (
unsigned long)outData.size();
47 &outData[0], &resSize, (
unsigned char*)inData,
48 (
unsigned long)inDataSize);
51 outData.resize(resSize);
60 const std::vector<unsigned char>& inData,
61 std::vector<unsigned char>& outData)
66 unsigned long resSize;
68 outData.resize(inData.size() + inData.size() / 1000 + 50);
69 resSize = (
unsigned long)outData.size();
71 &outData[0], &resSize, &inData[0], (
unsigned long)inData.size());
74 outData.resize(resSize);
83 void* inData,
size_t inDataSize,
CStream& out)
88 unsigned long resSize;
89 std::vector<unsigned char> outData;
91 outData.resize(inDataSize + inDataSize / 1000 + 50);
92 resSize = (
unsigned long)outData.size();
95 &outData[0], &resSize, (
unsigned char*)inData,
96 (
unsigned long)inDataSize);
99 outData.resize(resSize);
111 const std::vector<unsigned char>& inData,
CStream& out)
116 unsigned long resSize;
117 std::vector<unsigned char> outData;
118 outData.resize(inData.size() + inData.size() / 1000 + 50);
119 resSize = (
unsigned long)outData.size();
122 &outData[0], &resSize, &inData[0], (
unsigned long)inData.size());
126 outData.resize(resSize);
138 void* inData,
size_t inDataSize, std::vector<unsigned char>& outData,
139 size_t outDataEstimatedSize)
144 outData.resize(outDataEstimatedSize);
145 unsigned long actualOutSize;
148 &outData[0], &actualOutSize, (
unsigned char*)inData,
149 (
unsigned long)inDataSize);
153 outData.resize(actualOutSize);
162 void* inData,
size_t inDataSize,
void* outData,
size_t outDataBufferSize,
163 size_t& outDataActualSize)
168 unsigned long actualOutSize = (
unsigned long)outDataBufferSize;
171 (
unsigned char*)outData, &actualOutSize, (
unsigned char*)inData,
172 (
unsigned long)inDataSize);
176 outDataActualSize = actualOutSize;
185 CStream& inStream,
size_t inDataSize,
void* outData,
186 size_t outDataBufferSize,
size_t& outDataActualSize)
191 unsigned long actualOutSize = (
unsigned long)outDataBufferSize;
192 std::vector<unsigned char> inData;
194 inData.resize(inDataSize);
198 (
unsigned char*)outData, &actualOutSize, &inData[0],
199 (
unsigned long)inDataSize);
203 outDataActualSize = actualOutSize;
219 const int bytes2read = 1 << 20;
221 size_t total_bytes = 0;
229 total_bytes += act_read;
230 }
while (act_read == bytes2read);
232 buffer.resize(total_bytes);
241 const int compress_level)
243 #if MRPT_HAS_GZ_STREAMS 245 oss.open(file_path, compress_level);
246 if (!oss.fileOpenCorrectly())
return false;
274 const int compress_level)
277 if (in_data.empty())
return true;
279 #if MRPT_HAS_GZ_STREAMS 281 const unsigned int nPipeName =
286 #ifdef MRPT_OS_WINDOWS 289 format(
"\\\\.\\pipe\\mrpt_compress_gz_data_block_%u", nPipeName);
291 HANDLE hPipe = CreateNamedPipeA(
292 pipe_file_name.c_str(),
293 PIPE_ACCESS_DUPLEX | 0x00080000 ,
294 PIPE_TYPE_BYTE, PIPE_UNLIMITED_INSTANCES, in_data.size() + 1000,
295 in_data.size() + 1000, 0,
nullptr);
296 if (hPipe == INVALID_HANDLE_VALUE)
300 pipe_file_name =
format(
"/tmp/mrpt_compress_gz_data_block_%u", nPipeName);
309 pipe_file_name.c_str(),
format(
"wb%i", compress_level).c_str());
312 retVal = (int)in_data.size() ==
313 gzwrite(f, &in_data[0], in_data.size());
318 std::cerr <<
"[compress_gz_data_block] Error writing to pipe: " 319 << pipe_file_name << std::endl;
325 #ifdef MRPT_OS_WINDOWS 327 const size_t N = GetFileSize(hPipe,
nullptr);
330 out_gz_data.resize(N);
332 SetFilePointer(hPipe, 0,
nullptr, FILE_BEGIN);
335 ReadFile(hPipe, &out_gz_data[0], N, &nRead,
nullptr);
347 if (iss.
open(pipe_file_name))
350 out_gz_data.resize(M);
351 if (M) retVal = M == iss.
ReadBuffer(&out_gz_data[0], M);
363 #ifdef MRPT_OS_WINDOWS 366 remove(pipe_file_name.c_str());
382 if (in_gz_data.empty())
return true;
392 remove(tmp_file_name.c_str());
size_t ReadBuffer(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::vector< uint8_t > vector_byte
#define MRPT_END_WITH_CLEAN_UP(stuff)
#define THROW_EXCEPTION(msg)
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
bool vectorToBinaryFile(const vector_byte &vec, const std::string &fileName)
Saves a vector directly as a binary dump to a file:
bool decompress_gz_data_block(const vector_byte &in_gz_data, vector_byte &out_data)
Decompress an array of bytes storing a gz-compressed stream of data into a memory buffer...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
std::string getTempFileName()
Returns the name of a proposed temporary file name.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool decompress_gz_file(const std::string &file_path, vector_byte &buffer)
Decompress a gzip file (xxxx.gz) into a memory buffer.
GLsizei const GLchar ** string
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define CFileGZOutputStream
Saves data to a file and transparently compress the data using the given compression level...
bool compress_gz_file(const std::string &file_path, const vector_byte &buffer, const int compress_level=9)
Compress a memory buffer into a gzip file (xxxx.gz).
void compress(void *inData, size_t inDataSize, std::vector< unsigned char > &outData)
Compress an array of bytes into another one.
void decompress(void *inData, size_t inDataSize, std::vector< unsigned char > &outData, size_t outDataEstimatedSize)
Decompress an array of bytes into another one.
Compression using the "zip" algorithm and from/to gzip (gz) files.
bool compress_gz_data_block(const vector_byte &in_data, vector_byte &out_gz_data, const int compress_level=9)
Compress a memory buffer in gz-file format and return it as a block a memory.