GPAK  1.0.0
A general-purpose archive library
gpak_compressors.h
Go to the documentation of this file.
1 /**
2  * @file gpak_compressors.h
3  * @author AdamFull
4  * @date 23.04.2023
5  * @brief The gpak_compressors.h header file contains methods for compressing
6  * and decompressing files used in the Gpak library for managing game
7  * archives.
8  *
9  * This header file defines the compressor and decompressor functions for
10  * various compression algorithms used in the Gpak library. These functions
11  * are responsible for compressing and decompressing data stored within game
12  * archive files, enabling efficient storage and retrieval of game assets.
13  *
14  * The Gpak library supports a variety of compression algorithms, including
15  * (but not limited to): Deflate, LZ4, and Zstd. Additional compression
16  * algorithms can be added by implementing the required compressor and
17  * decompressor functions, and integrating them into the Gpak library.
18  *
19  * To use the compression and decompression functions provided by this header,
20  * include it alongside the main gpak.h header file and link against the Gpak
21  * library in your project.
22  */
23 
24 #ifndef GPAK_COMPRESSORS_H
25 #define GPAK_COMPRESSORS_H
26 
27 #define _DEFAULT_BLOCK_SIZE 4 * 1024 * 1024
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33  #include "gpak_export.h"
34  #include "gpak_data.h"
35 
36  /**
37  * @brief Performs no compression on the input file.
38  *
39  * This function reads data from the input file and writes it directly to the output file without any compression.
40  *
41  * @param _pak A pointer to the gpak_t.
42  * @param _infile A pointer to the input FILE.
43  * @param _outfile A pointer to the output FILE.
44  * @return The number of bytes written to the output file.
45  */
46  GPAK_API uint32_t _gpak_compressor_none(gpak_t* _pak, FILE* _infile, FILE* _outfile);
47 
48  /**
49  * @brief Performs no decompression on the input file.
50  *
51  * This function reads data from the input file and writes it directly to the output file without any decompression.
52  *
53  * @param _pak A pointer to the gpak_t.
54  * @param _infile A pointer to the input FILE.
55  * @param _outfile A pointer to the output FILE.
56  * @param _read_size The number of bytes to read from the input file.
57  * @return The number of bytes written to the output file.
58  */
59  GPAK_API uint32_t _gpak_decompressor_none(gpak_t* _pak, FILE* _infile, FILE* _outfile, size_t _read_size);
60 
61  /**
62  * @brief Compresses the input file using the Deflate algorithm.
63  *
64  * This function compresses the input file using the Deflate algorithm and writes the compressed data to the output file.
65  *
66  * @param _pak A pointer to the gpak_t.
67  * @param _infile A pointer to the input FILE.
68  * @param _outfile A pointer to the output FILE.
69  * @return The number of bytes written to the output file.
70  */
71  GPAK_API uint32_t _gpak_compressor_deflate(gpak_t* _pak, FILE* _infile, FILE* _outfile);
72 
73  /**
74  * @brief Decompresses the input file using the Inflate algorithm.
75  *
76  * This function decompresses the input file using the Inflate algorithm and writes the decompressed data to the output file.
77  *
78  * @param _pak A pointer to the gpak_t.
79  * @param _infile A pointer to the input FILE.
80  * @param _outfile A pointer to the output FILE.
81  * @param _read_size The number of bytes to read from the input file.
82  * @return The number of bytes written to the output file.
83  */
84  GPAK_API uint32_t _gpak_decompressor_inflate(gpak_t* _pak, FILE* _infile, FILE* _outfile, size_t _read_size);
85 
86  /**
87  * @brief Compresses the input file using the Zstandard (zstd) algorithm.
88  *
89  * This function compresses the input file using the Zstandard (zstd) algorithm and writes the compressed data to the output file.
90  *
91  * @param _pak A pointer to the gpak_t.
92  * @param _infile A pointer to the input FILE.
93  * @param _outfile A pointer to the output FILE.
94  * @return The number of bytes written to the output file.
95  */
96  GPAK_API uint32_t _gpak_compressor_zstd(gpak_t* _pak, FILE* _infile, FILE* _outfile);
97 
98  /**
99  * @brief Decompresses the input file using the Zstandard (zstd) algorithm.
100  * This function decompresses the input file using the Zstandard (zstd) algorithm and writes the decompressed data to the output file.
101  * @param _pak A pointer to the gpak_t.
102  * @param _infile A pointer to the input FILE.
103  * @param _outfile A pointer to the output FILE.
104  * @param _read_size The number of bytes to read from the input file.
105  * @return The number of bytes written to the output file.
106  */
107  GPAK_API uint32_t _gpak_decompressor_zstd(gpak_t* _pak, FILE* _infile, FILE* _outfile, size_t _read_size);
108 
109  /**
110  * @brief Generates a compression dictionary for the specified G-PAK archive.
111  * This function generates a compression dictionary for the specified G-PAK archive, which can be used to improve the compression ratio for certain algorithms.
112  * @param _pak A pointer to the gpak_t.
113  * @return A non-negative value if the dictionary generation is successful, or a negative value if an error occurred.
114  */
115  GPAK_API int32_t _gpak_compressor_generate_dictionary(gpak_t* _pak);
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif // GPAK_COMPRESSORS_H
GPAK_API uint32_t _gpak_compressor_deflate(gpak_t *_pak, FILE *_infile, FILE *_outfile)
GPAK_API uint32_t _gpak_compressor_none(gpak_t *_pak, FILE *_infile, FILE *_outfile)
GPAK_API uint32_t _gpak_decompressor_none(gpak_t *_pak, FILE *_infile, FILE *_outfile, size_t _read_size)
GPAK_API uint32_t _gpak_decompressor_inflate(gpak_t *_pak, FILE *_infile, FILE *_outfile, size_t _read_size)
GPAK_API uint32_t _gpak_decompressor_zstd(gpak_t *_pak, FILE *_infile, FILE *_outfile, size_t _read_size)
GPAK_API int32_t _gpak_compressor_generate_dictionary(gpak_t *_pak)
GPAK_API uint32_t _gpak_compressor_zstd(gpak_t *_pak, FILE *_infile, FILE *_outfile)