]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/easy_encoder.c
Add a rough explanation of --extreme to output of --help.
[icculus/xz.git] / src / liblzma / common / easy_encoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       easy_encoder.c
4 /// \brief      Easy .xz Stream encoder initialization
5 //
6 //  Copyright (C) 2008 Lasse Collin
7 //
8 //  This library is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Lesser General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2.1 of the License, or (at your option) any later version.
12 //
13 //  This library is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Lesser General Public License for more details.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #include "easy_preset.h"
21 #include "stream_encoder.h"
22
23
24 struct lzma_coder_s {
25         lzma_next_coder stream_encoder;
26         lzma_options_easy opt_easy;
27 };
28
29
30 static lzma_ret
31 easy_encode(lzma_coder *coder, lzma_allocator *allocator,
32                 const uint8_t *restrict in, size_t *restrict in_pos,
33                 size_t in_size, uint8_t *restrict out,
34                 size_t *restrict out_pos, size_t out_size, lzma_action action)
35 {
36         return coder->stream_encoder.code(
37                         coder->stream_encoder.coder, allocator,
38                         in, in_pos, in_size, out, out_pos, out_size, action);
39 }
40
41
42 static void
43 easy_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
44 {
45         lzma_next_end(&coder->stream_encoder, allocator);
46         lzma_free(coder, allocator);
47         return;
48 }
49
50
51 static lzma_ret
52 easy_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
53                 uint32_t preset, lzma_check check)
54 {
55         lzma_next_coder_init(easy_encoder_init, next, allocator);
56
57         if (next->coder == NULL) {
58                 next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
59                 if (next->coder == NULL)
60                         return LZMA_MEM_ERROR;
61
62                 next->code = &easy_encode;
63                 next->end = &easy_encoder_end;
64
65                 next->coder->stream_encoder = LZMA_NEXT_CODER_INIT;
66         }
67
68         if (lzma_easy_preset(&next->coder->opt_easy, preset))
69                 return LZMA_OPTIONS_ERROR;
70
71         return lzma_stream_encoder_init(&next->coder->stream_encoder,
72                         allocator, next->coder->opt_easy.filters, check);
73 }
74
75
76 extern LZMA_API(lzma_ret)
77 lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check)
78 {
79         lzma_next_strm_init(easy_encoder_init, strm, preset, check);
80
81         strm->internal->supported_actions[LZMA_RUN] = true;
82         strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
83         strm->internal->supported_actions[LZMA_FULL_FLUSH] = true;
84         strm->internal->supported_actions[LZMA_FINISH] = true;
85
86         return LZMA_OK;
87 }