aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/easy_encoder.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-11-14 18:59:19 +0200
committerLasse Collin <lasse.collin@tukaani.org>2009-11-14 18:59:19 +0200
commit418d64a32e8144210f98a810738fed5a897e8367 (patch)
treee3dce06dfd250fd659d922aaed914f6cc93cd2c8 /src/liblzma/common/easy_encoder.c
parentFix wrong function name in the previous commit. (diff)
downloadxz-418d64a32e8144210f98a810738fed5a897e8367.tar.xz
Fix a design error in liblzma API.
Originally the idea was that using LZMA_FULL_FLUSH with Stream encoder would read the filter chain from the same array that was used to intialize the Stream encoder. Since most apps wouldn't use LZMA_FULL_FLUSH, most apps wouldn't need to keep the filter chain available after initializing the Stream encoder. However, due to my mistake, it actually required keeping the array always available. Since setting the new filter chain via the array used at initialization time is not a nice way to do it for a couple of reasons, this commit ditches it and introduces lzma_filters_update(). This new function replaces also the "persistent" flag used by LZMA2 (and to-be-designed Subblock filter), which was also an ugly thing to do. Thanks to Alexey Tourbin for reminding me about the problem that Stream encoder used to require keeping the filter chain allocated.
Diffstat (limited to '')
-rw-r--r--src/liblzma/common/easy_encoder.c63
1 files changed, 4 insertions, 59 deletions
diff --git a/src/liblzma/common/easy_encoder.c b/src/liblzma/common/easy_encoder.c
index 5e2641c9..d13ccd73 100644
--- a/src/liblzma/common/easy_encoder.c
+++ b/src/liblzma/common/easy_encoder.c
@@ -14,67 +14,12 @@
#include "stream_encoder.h"
-struct lzma_coder_s {
- lzma_next_coder stream_encoder;
- lzma_options_easy opt_easy;
-};
-
-
-static lzma_ret
-easy_encode(lzma_coder *coder, lzma_allocator *allocator,
- const uint8_t *restrict in, size_t *restrict in_pos,
- size_t in_size, uint8_t *restrict out,
- size_t *restrict out_pos, size_t out_size, lzma_action action)
-{
- return coder->stream_encoder.code(
- coder->stream_encoder.coder, allocator,
- in, in_pos, in_size, out, out_pos, out_size, action);
-}
-
-
-static void
-easy_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
-{
- lzma_next_end(&coder->stream_encoder, allocator);
- lzma_free(coder, allocator);
- return;
-}
-
-
-static lzma_ret
-easy_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
- uint32_t preset, lzma_check check)
-{
- lzma_next_coder_init(&easy_encoder_init, next, allocator);
-
- if (next->coder == NULL) {
- next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
- if (next->coder == NULL)
- return LZMA_MEM_ERROR;
-
- next->code = &easy_encode;
- next->end = &easy_encoder_end;
-
- next->coder->stream_encoder = LZMA_NEXT_CODER_INIT;
- }
-
- if (lzma_easy_preset(&next->coder->opt_easy, preset))
- return LZMA_OPTIONS_ERROR;
-
- return lzma_stream_encoder_init(&next->coder->stream_encoder,
- allocator, next->coder->opt_easy.filters, check);
-}
-
-
extern LZMA_API(lzma_ret)
lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check)
{
- lzma_next_strm_init(easy_encoder_init, strm, preset, check);
-
- strm->internal->supported_actions[LZMA_RUN] = true;
- strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
- strm->internal->supported_actions[LZMA_FULL_FLUSH] = true;
- strm->internal->supported_actions[LZMA_FINISH] = true;
+ lzma_options_easy opt_easy;
+ if (lzma_easy_preset(&opt_easy, preset))
+ return LZMA_OPTIONS_ERROR;
- return LZMA_OK;
+ return lzma_stream_encoder(strm, opt_easy.filters, check);
}