Compress all instructions (closes #19 github issue)

This commit is contained in:
Keith Winstein
2012-02-26 04:39:13 -05:00
parent f0886a1dda
commit 7a9f92d7f1
7 changed files with 80 additions and 4 deletions
+32
View File
@@ -0,0 +1,32 @@
#include <zlib.h>
#include <assert.h>
#include "compressor.h"
using namespace Network;
using namespace std;
string Compressor::compress_str( const string input )
{
size_t len = BUFFER_SIZE;
assert( Z_OK == compress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
return string( reinterpret_cast<char *>( buffer ), len );
}
string Compressor::uncompress_str( const string input )
{
size_t len = BUFFER_SIZE;
assert( Z_OK == uncompress( buffer, &len,
reinterpret_cast<const unsigned char *>( input.data() ),
input.size() ) );
return string( reinterpret_cast<char *>( buffer ), len );
}
/* construct on first use */
Compressor & Network::get_compressor( void )
{
static Compressor the_compressor;
return the_compressor;
}