1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Easy Multi-Block Stream encoder initialization
6 // Copyright (C) 2008 Lasse Collin
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.
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.
18 ///////////////////////////////////////////////////////////////////////////////
20 #include "easy_common.h"
21 #include "stream_encoder_multi.h"
25 lzma_next_coder encoder;
26 lzma_options_stream options;
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)
36 return coder->encoder.code(coder->encoder.coder, allocator,
37 in, in_pos, in_size, out, out_pos, out_size, action);
42 easy_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
44 lzma_next_coder_end(&coder->encoder, allocator);
45 lzma_free(coder, allocator);
51 easy_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
52 lzma_easy_level level, lzma_easy_level metadata_level,
53 const lzma_extra *header, const lzma_extra *footer)
55 if (next->coder == NULL) {
56 next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
57 if (next->coder == NULL)
58 return LZMA_MEM_ERROR;
60 next->code = &easy_encode;
61 next->end = &easy_encoder_end;
63 next->coder->encoder = LZMA_NEXT_CODER_INIT;
66 next->coder->options = (lzma_options_stream){
67 .check = LZMA_CHECK_CRC32,
69 .uncompressed_size = LZMA_VLI_VALUE_UNKNOWN,
75 if (lzma_easy_set_filters(next->coder->options.filters, level)
76 || lzma_easy_set_filters(
77 next->coder->options.metadata_filters,
79 return LZMA_HEADER_ERROR;
81 return lzma_stream_encoder_multi_init(&next->coder->encoder,
82 allocator, &next->coder->options);
86 extern LZMA_API lzma_ret
87 lzma_easy_encoder_multi(lzma_stream *strm,
88 lzma_easy_level level, lzma_easy_level metadata_level,
89 const lzma_extra *header, const lzma_extra *footer)
91 // This is more complicated than lzma_easy_encoder_single(),
92 // because lzma_stream_encoder_multi() wants that the options
93 // structure is available until the encoding is finished.
94 lzma_next_strm_init(strm, easy_encoder_init,
95 level, metadata_level, header, footer);
97 strm->internal->supported_actions[LZMA_RUN] = true;
98 strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
99 strm->internal->supported_actions[LZMA_FULL_FLUSH] = true;
100 strm->internal->supported_actions[LZMA_FINISH] = true;