-
Notifications
You must be signed in to change notification settings - Fork 0
/
compressor.hpp
62 lines (52 loc) · 2.32 KB
/
compressor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef ARCHRONIS_COMPRESSOR_HPP
#define ARCHRONIS_COMPRESSOR_HPP
#include "lib/byte_str.h"
#include "lzw.hpp"
#include "lib/vector.h"
class compressor
{
// Buffer for data that is compressed and densely packed
// This kind of data is stored in archives
byte_str packed_buf;
// Buffer for raw data that is going to be compressed or written on disk after decompression
byte_str uncompressed_buf;
// Buffer for intermediate representation of compressed data as sequences of 16-bit codes
// Only 12 bit out of 16 are significant
tld::vector<pos_t> compressed_buf;
public:
/// Creates compressor with pre-allocated buffers
compressor();
/// Default constructor
~compressor() = default;
/**
* @brief Read data from a stream and write compressed data to the other stream
* @param input_fs input file stream
* @param output_fs output file stream
* @param input_size number of bytes to be read from input
* @returns Always OK, you need to turn on exceptions for the streams
*/
int compressBlock(std::ifstream& input_fs, std::ofstream& output_fs, std::size_t input_size);
/**
* @brief Read compressed block of data from one stream and write decompressed data to the other stream
* @param input_fs input file stream
* @param output_fs output file stream
* @returns On success zero is returned. Either ERR_CRC or ERR_DECODE if returned if decompression was not successfull
*/
int decompressBlock(std::ifstream& input_fs, std::ofstream& output_fs);
/**
* @brief Read data from a stream and write compressed data to the other stream
* @param input_fs input file stream
* @param output_fs output file stream
* @param input_size number of bytes to be read from input
* @returns Always OK, you need to turn on exceptions for the streams
* @details Same as compressBlock, but processes files blockwise (for large files)
*/
int compressFile(std::ifstream& input_fs, std::ofstream& output_fs, std::size_t file_size);
/**
* @brief Read sequence of compressed blocks and write decompressed data to output_fs
* @param input_fs input file stream
* @param output_fs output file stream
*/
int decompressFile(std::ifstream& input_fs, std::ofstream& output_fs);
};
#endif // ARCHRONIS_COMPRESSOR_HPP