aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/api/lzma/easy.h
blob: d83a79a252433e13c73c5fb396b5487cd6662b10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
 * \file        lzma/easy.h
 * \brief       Easy to use encoder initialization
 *
 * \author      Copyright (C) 1999-2006 Igor Pavlov
 * \author      Copyright (C) 2008 Lasse Collin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

#ifndef LZMA_H_INTERNAL
#	error Never include this file directly. Use <lzma.h> instead.
#endif


/**
 * \brief       Compression level names for lzma_easy_* functions
 *
 * At the moment, all the compression levels support LZMA_SYNC_FLUSH.
 * In future there may be levels that don't support LZMA_SYNC_FLUSH.
 * However, the LZMA_SYNC_FLUSH support won't be removed from the
 * existing compression levels.
 *
 * \note        If liblzma is built without encoder support, or with some
 *              filters disabled, some of the compression levels may be
 *              unsupported. In that case, the initialization functions
 *              will return LZMA_HEADER_ERROR.
 */
typedef enum {
	LZMA_EASY_COPY,
		/**<
		 * No compression; the data is just wrapped into .lzma
		 * container.
		 */

	LZMA_EASY_LZMA_1,
		/**<
		 * LZMA filter with fast compression (fast in terms of LZMA).
		 * If you are interested in the exact options used, see
		 * lzma_preset_lzma[0]. Note that the exact options may
		 * change between liblzma versions.
		 *
		 * At the moment, the command line tool uses these settings
		 * when `lzma -1' is used. In future, the command line tool
		 * may default to some more complex way to determine the
		 * settings used e.g. the type of files being compressed.
		 *
		 * LZMA_EASY_LZMA_2 is equivalent to lzma_preset_lzma[1]
		 * and so on.
		 */

	LZMA_EASY_LZMA_2,
	LZMA_EASY_LZMA_3,
	LZMA_EASY_LZMA_4,
	LZMA_EASY_LZMA_5,
	LZMA_EASY_LZMA_6,
	LZMA_EASY_LZMA_7,
	LZMA_EASY_LZMA_8,
	LZMA_EASY_LZMA_9,
} lzma_easy_level;


/**
 * \brief       Default compression level
 *
 * Data Blocks contain the actual compressed data. It's not straightforward
 * to recommend a default level, because in some cases keeping the resource
 * usage relatively low is more important that getting the maximum
 * compression ratio.
 */
#define LZMA_EASY_DEFAULT LZMA_EASY_LZMA_7


/**
 * \brief       Calculates rough memory requirements of a compression level
 *
 * This function is a wrapper for lzma_memory_usage(), which is declared
 * in lzma/filter.h.
 *
 * \return      Approximate memory usage of the encoder with the given
 *              compression level in mebibytes (value * 1024 * 1024 bytes).
 *              On error (e.g. compression level is not supported),
 *              UINT32_MAX is returned.
 */
extern uint32_t lzma_easy_memory_usage(lzma_easy_level level);


/**
 * \brief       Initializes .lzma Stream encoder
 *
 * This function is intended for those who just want to use the basic LZMA
 * features (that is, most developers out there). Lots of assumptions are
 * made, which are correct or at least good enough for most situations.
 *
 * \param       strm    Pointer to lzma_stream that is at least initialized
 *                      with LZMA_STREAM_INIT.
 * \param       level   Compression level to use. This selects a set of
 *                      compression settings from a list of compression
 *                      presets.
 *
 * \return      - LZMA_OK: Initialization succeeded. Use lzma_code() to
 *                encode your data.
 *              - LZMA_MEM_ERROR: Memory allocation failed. All memory
 *                previously allocated for *strm is now freed.
 *              - LZMA_HEADER_ERROR: The given compression level is not
 *                supported by this build of liblzma.
 *
 * If initialization succeeds, use lzma_code() to do the actual encoding.
 * Valid values for `action' (the second argument of lzma_code()) are
 * LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
 * there may be compression levels that don't support LZMA_SYNC_FLUSH.
 */
extern lzma_ret lzma_easy_encoder(lzma_stream *strm, lzma_easy_level level);