]> wimlib.net Git - wimlib/blob - include/wimlib/compress_chunks.h
wimlib_overwrite(): Don't create multiple packs per WIM
[wimlib] / include / wimlib / compress_chunks.h
1 #ifndef _WIMLIB_COMPRESS_CHUNK_H
2 #define _WIMLIB_COMPRESS_CHUNK_H
3
4 #include <wimlib/types.h>
5
6 struct wimlib_lzx_context;
7
8 unsigned
9 compress_chunk(const void * uncompressed_data,
10                unsigned uncompressed_len,
11                void *compressed_data,
12                int out_ctype,
13                struct wimlib_lzx_context *comp_ctx);
14
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
19  * chunks).  */
20 struct chunk_compressor {
21         /* Variables set by the chunk compressor when it is created.  */
22         int out_ctype;
23         u32 out_chunk_size;
24         unsigned num_threads;
25
26         /* Free the chunk compressor.  */
27         void (*destroy)(struct chunk_compressor *);
28
29         /* Submit a chunk of uncompressed data for compression.
30          *
31          * The chunk must have size greater than 0 and less than or equal to
32          * @out_chunk_size.
33          *
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);
39
40         /* Get the next chunk of compressed data.
41          *
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.
47          *
48          * Chunks will be returned in the same order in which they were
49          * submitted for compression.
50          *
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.
54          *
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 *);
60 };
61
62
63 /* Functions that return implementations of the chunk_compressor interface.  */
64
65 int
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);
69
70 int
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);
74
75 #endif