aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/easy_encoder.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-02-17 10:43:00 +0200
committerLasse Collin <lasse.collin@tukaani.org>2009-02-17 10:43:00 +0200
commit489a3dbaa0465f04400804e956a1cfbbee3654a2 (patch)
tree9456c3fde0e0fdae8e006799338f41dd34508487 /src/liblzma/common/easy_encoder.c
parentMake physmem.h work on old Windows versions. (diff)
downloadxz-489a3dbaa0465f04400804e956a1cfbbee3654a2.tar.xz
Added lzma_easy_buffer_encode(). Splitted easy.c into small
pieces to avoid unneeded dependencies making statically linked applications bigger than needed.
Diffstat (limited to 'src/liblzma/common/easy_encoder.c')
-rw-r--r--src/liblzma/common/easy_encoder.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/liblzma/common/easy_encoder.c b/src/liblzma/common/easy_encoder.c
new file mode 100644
index 00000000..4a6709c6
--- /dev/null
+++ b/src/liblzma/common/easy_encoder.c
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file easy_encoder.c
+/// \brief Easy .xz Stream encoder initialization
+//
+// 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.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "easy_preset.h"
+#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;
+
+ return LZMA_OK;
+}