libcruft-util/cruft/util/zlib.hpp

61 lines
1.5 KiB
C++
Raw Permalink Normal View History

2013-07-13 15:28:29 +10:00
/*
2018-08-04 15:14:06 +10:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
2013-07-13 15:28:29 +10:00
*
* Copyright 2013 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
2013-07-13 15:28:29 +10:00
#include <stdexcept>
#include <string>
#include <zlib.h>
namespace cruft {
2013-07-13 15:28:29 +10:00
namespace zlib {
extern const char* version (void);
extern const char* code_to_string (int);
2013-07-13 15:28:29 +10:00
extern void compress (uint8_t *dst, size_t dst_len,
const uint8_t *src, size_t src_len,
int level);
extern size_t compress_bound (size_t len);
extern size_t uncompress (uint8_t *dst, size_t dst_len,
const uint8_t *src, size_t src_len);
class stream {
public:
public:
stream();
~stream();
int deflate (bool flush = false);
int inflate (bool flush = false);
};
class error : public std::runtime_error {
public:
static void try_code (int code);
static void throw_code (int code);
explicit error(const std::string&);
2013-07-13 15:28:29 +10:00
};
template <int CODE>
class code_error : public error {
public:
code_error(void):
error (code_to_string (CODE))
{ ; }
2013-07-13 15:28:29 +10:00
};
}
}