zutils.cpp File Reference

Implementation of Zlib-related utility methods. More...

#include <hn/hnprec.h>
#include "zutils.h"
#include <zlib.h>
#include <hn/log.h>
#include <hn/utils.h>

Go to the source code of this file.


Namespaces

namespace  Zlib

Functions

std::string compress (const std::string &input)
 Compresses the passed data, returning compressed data.
std::string decompress (const std::string &input, uint32_t bufsize)
 Decompresses passed data.

Detailed Description

Implementation of Zlib-related utility methods.

Definition in file zutils.cpp.


Function Documentation

std::string Zlib::compress const std::string &  input  ) 
 

Compresses the passed data, returning compressed data.

Parameters:
input Data to be compressed
Returns:
Compressed data. May be empty if compression fails.

Definition at line 30 of file zutils.cpp.

Referenced by Detail::UploadInfo::compress(), and ED2KPacket::Packet::makePacket().

std::string Zlib::decompress const std::string &  input,
uint32_t  bufsize = 0
 

Decompresses passed data.

Parameters:
input Data to be uncompressed
bufsize Suggested buffer size. If left at default value, the method attempts to guess the internal buffer size for unpacking itself.
Returns:
Unpacked data, or empty string if something goes wrong
Exceptions:
std::runtime_error if decompression fails
Note:
This function may call itself recursivly if the destination buffer size was not big enough to unpack the data (thus the second parameter also). The recursion ends either when the unpacking succeeds, or when destination buffer size exceeds 1MB. If you want to decompress data resulting in larger amount of unpacket data than 1MB, explicitly specify the buffer size as parameter.

Definition at line 68 of file zutils.cpp.

Referenced by ED2KPacket::Packet::makePacket(), and ED2KParser< Parent >::readPacket().