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