15 #ifdef MRPT_OS_WINDOWS 16 #define WIN32_LEAN_AND_MEAN 39 std::vector<unsigned char> &outData)
44 unsigned long resSize;
46 outData.resize(inDataSize+inDataSize/1000+50);
47 resSize = (
unsigned long)outData.size();
51 (
unsigned char*)inData,
52 (
unsigned long)inDataSize
56 outData.resize(resSize);
59 printf(
"[zlib] Error code=%i\n",ret);\
67 const std::vector<unsigned char> &inData,
68 std::vector<unsigned char> &outData)
73 unsigned long resSize;
75 outData.resize(inData.size()+inData.size()/1000+50);
76 resSize = (
unsigned long)outData.size();
81 (
unsigned long)inData.size()
85 outData.resize(resSize);
88 printf(
"[zlib] Error code=%i\n",ret);\
103 unsigned long resSize;
104 std::vector<unsigned char> outData;
106 outData.resize(inDataSize+inDataSize/1000+50);
107 resSize = (
unsigned long)outData.size();
112 (
unsigned char*)inData,
113 (
unsigned long)inDataSize
117 outData.resize(resSize);
123 printf(
"[zlib] Error code=%i\n",ret);\
132 const std::vector<unsigned char> &inData,
138 unsigned long resSize;
139 std::vector<unsigned char> outData;
140 outData.resize(inData.size()+inData.size()/1000+50);
141 resSize = (
unsigned long)outData.size();
147 (
unsigned long)inData.size()
152 outData.resize(resSize);
158 printf(
"[zlib] Error code=%i\n",ret);\
168 std::vector<unsigned char> &outData,
169 size_t outDataEstimatedSize)
174 outData.resize( outDataEstimatedSize );
175 unsigned long actualOutSize;
180 (
unsigned char*)inData,
181 (
unsigned long)inDataSize
186 outData.resize(actualOutSize);
189 printf(
"[zlib] Error code=%i\n",ret);\
200 size_t outDataBufferSize,
201 size_t &outDataActualSize)
206 unsigned long actualOutSize = (
unsigned long)outDataBufferSize;
209 (
unsigned char*)outData,
211 (
unsigned char*)inData,
212 (
unsigned long)inDataSize
217 outDataActualSize = actualOutSize;
220 printf(
"[zlib] Error code=%i\n",ret);\
231 size_t outDataBufferSize,
232 size_t &outDataActualSize)
237 unsigned long actualOutSize = (
unsigned long)outDataBufferSize;
238 std::vector<unsigned char> inData;
240 inData.resize(inDataSize);
241 inStream.
ReadBuffer( &inData[0], inDataSize );
244 (
unsigned char*)outData,
247 (
unsigned long)inDataSize
252 outDataActualSize = actualOutSize;
255 printf(
"[zlib] Error code=%i\n",ret);\
271 const int bytes2read = 1 << 20;
273 size_t total_bytes = 0;
281 total_bytes += act_read;
282 }
while (act_read==bytes2read);
284 buffer.resize( total_bytes );
294 const int compress_level
297 #if MRPT_HAS_GZ_STREAMS 299 oss.open(file_path,compress_level);
300 if (!oss.fileOpenCorrectly())
310 catch(...) {
return false; }
328 const int compress_level
335 #if MRPT_HAS_GZ_STREAMS 341 #ifdef MRPT_OS_WINDOWS 343 pipe_file_name =
format(
"\\\\.\\pipe\\mrpt_compress_gz_data_block_%u",nPipeName);
345 HANDLE hPipe = CreateNamedPipeA(
346 pipe_file_name.c_str(),
347 PIPE_ACCESS_DUPLEX | 0x00080000 ,
349 PIPE_UNLIMITED_INSTANCES,
354 if (hPipe==INVALID_HANDLE_VALUE)
THROW_EXCEPTION(
"Error creating named pipe for gz-file compression");
357 pipe_file_name =
format(
"/tmp/mrpt_compress_gz_data_block_%u",nPipeName);
366 gzFile f = gzopen(pipe_file_name.c_str(),
format(
"wb%i",compress_level).c_str() );
369 retVal = (int)in_data.size() == gzwrite(f,&in_data[0], in_data.size());
374 std::cerr <<
"[compress_gz_data_block] Error writing to pipe: " << pipe_file_name << std::endl;
380 #ifdef MRPT_OS_WINDOWS 382 const size_t N = GetFileSize(hPipe,NULL);
385 out_gz_data.resize(N);
387 SetFilePointer(hPipe,0,NULL, FILE_BEGIN);
390 ReadFile(hPipe,&out_gz_data[0],N,&nRead,NULL);
402 if (iss.
open(pipe_file_name))
405 out_gz_data.resize(M);
407 retVal = M==iss.
ReadBuffer(&out_gz_data[0],M);
419 #ifdef MRPT_OS_WINDOWS 422 remove(pipe_file_name.c_str());
440 if (in_gz_data.empty())
return true;
448 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 BASE_IMPEXP vectorToBinaryFile(const vector_byte &vec, const std::string &fileName)
Saves a vector directly as a binary dump to a file:
bool BASE_IMPEXP 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 BASE_IMPEXP getTempFileName()
Returns the name of a proposed temporary file name.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool BASE_IMPEXP 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 BASE_IMPEXP 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 BASE_IMPEXP compress(void *inData, size_t inDataSize, std::vector< unsigned char > &outData)
Compress an array of bytes into another one.
void BASE_IMPEXP 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 BASE_IMPEXP 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.