1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file easy_encoder.c
4 /// \brief Easy .xz 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_preset.h"
21 #include "stream_encoder.h"
25 lzma_next_coder stream_encoder;
26 lzma_options_easy opt_easy;
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->stream_encoder.code(
37 coder->stream_encoder.coder, allocator,
38 in, in_pos, in_size, out, out_pos, out_size, action);
43 easy_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
45 lzma_next_end(&coder->stream_encoder, allocator);
46 lzma_free(coder, allocator);
52 easy_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
53 uint32_t preset, lzma_check check)
55 lzma_next_coder_init(easy_encoder_init, next, allocator);
57 if (next->coder == NULL) {
58 next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
59 if (next->coder == NULL)
60 return LZMA_MEM_ERROR;
62 next->code = &easy_encode;
63 next->end = &easy_encoder_end;
65 next->coder->stream_encoder = LZMA_NEXT_CODER_INIT;
68 if (lzma_easy_preset(&next->coder->opt_easy, preset))
69 return LZMA_OPTIONS_ERROR;
71 return lzma_stream_encoder_init(&next->coder->stream_encoder,
72 allocator, next->coder->opt_easy.filters, check);
76 extern LZMA_API(lzma_ret)
77 lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check)
79 lzma_next_strm_init(easy_encoder_init, strm, preset, check);
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;