4 * Interface for serial/parallel chunk compression.
7 #ifndef _WIMLIB_CHUNK_COMPRESSOR_H
8 #define _WIMLIB_CHUNK_COMPRESSOR_H
10 #include <wimlib/types.h>
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
17 struct chunk_compressor {
18 /* Variables set by the chunk compressor when it is created. */
23 /* Free the chunk compressor. */
24 void (*destroy)(struct chunk_compressor *);
26 /* Submit a chunk of uncompressed data for compression.
28 * The chunk must have size greater than 0 and less than or equal to
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 *, size_t);
37 /* Get the next chunk of compressed data.
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.
45 * Chunks will be returned in the same order in which they were
46 * submitted for compression.
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.
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 *);
60 /* Functions that return implementations of the chunk_compressor interface. */
62 #ifdef ENABLE_MULTITHREADED_COMPRESSION
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);
70 new_serial_chunk_compressor(int out_ctype, u32 out_chunk_size,
71 struct chunk_compressor **compressor_ret);
73 #endif /* _WIMLIB_CHUNK_COMPRESSOR_H */