]> wimlib.net Git - wimlib/blob - include/wimlib/chunk_compressor.h
Header fixes
[wimlib] / include / wimlib / chunk_compressor.h
1 /*
2  * chunk_compressor.h
3  *
4  * Interface for serial/parallel chunk compression.
5  */
6
7 #ifndef _WIMLIB_CHUNK_COMPRESSOR_H
8 #define _WIMLIB_CHUNK_COMPRESSOR_H
9
10 #include "wimlib/types.h"
11
12 /* Interface for chunk compression.  Users can submit chunks of data to be
13  * compressed, then retrieve them later in order.  This interface can be
14  * implemented either in serial (having the calling thread compress the chunks
15  * itself) or in parallel (having other threads asynchronously compress the
16  * chunks).  */
17 struct chunk_compressor {
18         /* Variables set by the chunk compressor when it is created.  */
19         int out_ctype;
20         u32 out_chunk_size;
21         unsigned num_threads;
22
23         /* Free the chunk compressor.  */
24         void (*destroy)(struct chunk_compressor *);
25
26         /* Submit a chunk of uncompressed data for compression.
27          *
28          * The chunk must have size greater than 0 and less than or equal to
29          * @out_chunk_size.
30          *
31          * The return value is %true if the chunk was successfully submitted, or
32          * %false if the chunk compressor does not have space for the chunk at
33          * the present time.  In the latter case, get_chunk() must be called to
34          * retrieve a compressed chunk before trying again.  */
35         bool (*submit_chunk)(struct chunk_compressor *, const void *, u32);
36
37         /* Get the next chunk of compressed data.
38          *
39          * The compressed data, along with its size and the size of the original
40          * uncompressed chunk, are returned in the locations pointed to by
41          * arguments 2-4.  The compressed data is in storage internal to the
42          * chunk compressor, and it cannot be accessed beyond any subsequent
43          * calls to the chunk compressor.
44          *
45          * Chunks will be returned in the same order in which they were
46          * submitted for compression.
47          *
48          * The resulting compressed length may be up to the uncompressed length.
49          * In the case where they are equal, the returned data is actually the
50          * uncompressed data, not the compressed data.
51          *
52          * The return value is %true if a chunk of compressed data was
53          * successfully retrieved, or %false if there are no chunks currently
54          * being compressed.  */
55         bool (*get_chunk)(struct chunk_compressor *,
56                           const void **, u32 *, u32 *);
57 };
58
59
60 /* Functions that return implementations of the chunk_compressor interface.  */
61
62 #ifdef ENABLE_MULTITHREADED_COMPRESSION
63 int
64 new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
65                               unsigned num_threads, u64 max_memory,
66                               struct chunk_compressor **compressor_ret);
67 #endif
68
69 int
70 new_serial_chunk_compressor(int out_ctype, u32 out_chunk_size,
71                             struct chunk_compressor **compressor_ret);
72
73 #endif /* _WIMLIB_CHUNK_COMPRESSOR_H  */