Squash  0.7.0
codec.c
1 /* Copyright (c) 2013-2015 The Squash Authors
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use, copy,
7  * modify, merge, publish, distribute, sublicense, and/or sell copies
8  * of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  * Evan Nemerson <evan@nemerson.com>
25  */
26 
27 #define _POSIX_C_SOURCE 200809L
28 
29 #include <assert.h>
30 #include <string.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <unistd.h>
34 #include <stdio.h>
35 #include <strings.h>
36 
37 #if !defined(_WIN32)
38 #include <sys/mman.h>
39 #endif
40 
41 #include "internal.h"
42 #include "tinycthread/source/tinycthread.h"
43 
201 int
202 squash_codec_compare (SquashCodec* a, SquashCodec* b) {
203  assert (a != NULL);
204  assert (b != NULL);
205 
206  return strcmp (a->name, b->name);
207 }
208 
209 int
210 squash_codec_extension_compare (SquashCodec* a, SquashCodec* b) {
211  assert (a != NULL);
212  assert (b != NULL);
213 
214  return strcmp (a->extension, b->extension);
215 }
216 
297 const char*
298 squash_codec_get_name (SquashCodec* codec) {
299  assert (codec != NULL);
300 
301  return codec->name;
302 }
303 
310 unsigned int
311 squash_codec_get_priority (SquashCodec* codec) {
312  assert (codec != NULL);
313 
314  return codec->priority;
315 }
316 
323 SquashPlugin*
324 squash_codec_get_plugin (SquashCodec* codec) {
325  assert (codec != NULL);
326 
327  return codec->plugin;
328 }
329 
347 squash_codec_init (SquashCodec* codec) {
348  return squash_plugin_init_codec (codec->plugin, codec, &(codec->impl));
349 }
350 
357 SquashCodecImpl*
358 squash_codec_get_impl (SquashCodec* codec) {
359  if (codec->initialized != 1) {
360  SquashStatus res = squash_plugin_init_codec (codec->plugin, codec, &(codec->impl));
361  if (res != SQUASH_OK) {
362  return NULL;
363  }
364  }
365 
366  return &(codec->impl);
367 }
368 
382 size_t
384  size_t compressed_length,
385  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)]) {
386  SquashCodecImpl* impl = NULL;
387 
388  assert (codec != NULL);
389  assert (compressed_length > 0);
390  assert (compressed != NULL);
391 
392  impl = squash_codec_get_impl (codec);
393  if (impl != NULL && impl->get_uncompressed_size != NULL) {
394  return impl->get_uncompressed_size (codec, compressed_length, compressed);
395  } else {
396  return 0;
397  }
398 }
399 
400 size_t
401 squash_get_uncompressed_size (const char* codec,
402  size_t compressed_length,
403  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)]) {
404  assert (codec != NULL);
405  assert (compressed_length > 0);
406  assert (compressed != NULL);
407 
408  SquashCodec* codec_real = squash_get_codec (codec);
409  if (codec_real == NULL)
410  return 0;
411 
412  return squash_codec_get_uncompressed_size (codec_real, compressed_length, compressed);
413 }
414 
432 size_t
433 squash_codec_get_max_compressed_size (SquashCodec* codec, size_t uncompressed_length) {
434  SquashCodecImpl* impl = NULL;
435 
436  assert (codec != NULL);
437 
438  impl = squash_codec_get_impl (codec);
439  if (impl != NULL && impl->get_max_compressed_size != NULL) {
440  return impl->get_max_compressed_size (codec, uncompressed_length);
441  } else {
442  return 0;
443  }
444 }
445 
464 size_t
465 squash_get_max_compressed_size (const char* codec, size_t uncompressed_length) {
466  SquashCodec* codec_real = squash_get_codec (codec);
467 
468  if (codec_real == NULL) {
469  return 0;
470  }
471 
472  return squash_codec_get_max_compressed_size (codec_real, uncompressed_length);
473 }
474 
484 SquashStream*
485 squash_codec_create_stream_with_options (SquashCodec* codec, SquashStreamType stream_type, SquashOptions* options) {
486  SquashCodecImpl* impl = NULL;
487 
488  assert (codec != NULL);
489  assert (stream_type == SQUASH_STREAM_COMPRESS || stream_type == SQUASH_STREAM_DECOMPRESS);
490 
491  impl = squash_codec_get_impl (codec);
492  if (impl == NULL) {
493  return NULL;
494  }
495 
496  if (impl->create_stream != NULL) {
497  return impl->create_stream (codec, stream_type, options);
498  } else {
499  if (impl->process_stream == NULL) {
500  return (SquashStream*) squash_buffer_stream_new (codec, stream_type, options);
501  } else {
502  return NULL;
503  }
504  }
505 }
506 
516 SquashStream*
517 squash_codec_create_stream (SquashCodec* codec, SquashStreamType stream_type, ...) {
518  va_list ap;
519  SquashOptions* options;
520 
521  assert (codec != NULL);
522  assert (stream_type == SQUASH_STREAM_COMPRESS || stream_type == SQUASH_STREAM_DECOMPRESS);
523 
524  va_start (ap, stream_type);
525  options = squash_options_newv (codec, ap);
526  va_end (ap);
527 
528  return squash_codec_create_stream_with_options (codec, stream_type, options);
529 }
530 
546  size_t* compressed_length,
547  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
548  size_t uncompressed_length,
549  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
550  SquashOptions* options) {
551  SquashCodecImpl* impl = NULL;
552 
553  assert (codec != NULL);
554 
555  assert (compressed != NULL);
556  assert (uncompressed != NULL);
557 
558  impl = squash_codec_get_impl (codec);
559  if (impl == NULL)
561 
562  if (compressed == uncompressed)
564 
565  if (impl->compress_buffer ||
566  impl->compress_buffer_unsafe) {
567  size_t max_compressed_length = squash_codec_get_max_compressed_size (codec, uncompressed_length);
568 
569  if (*compressed_length >= max_compressed_length) {
570  if (impl->compress_buffer_unsafe != NULL) {
571  return impl->compress_buffer_unsafe (codec,
572  compressed_length, compressed,
573  uncompressed_length, uncompressed,
574  options);
575  } else {
576  return impl->compress_buffer (codec,
577  compressed_length, compressed,
578  uncompressed_length, uncompressed,
579  options);
580  }
581  } else if (impl->compress_buffer != NULL) {
582  return impl->compress_buffer (codec,
583  compressed_length, compressed,
584  uncompressed_length, uncompressed,
585  options);
586  } else {
587  SquashStatus status;
588  uint8_t* tmp_buf = malloc (max_compressed_length);
589  if (tmp_buf == NULL)
590  return squash_error (SQUASH_MEMORY);
591 
592  status = impl->compress_buffer_unsafe (codec,
593  &max_compressed_length, tmp_buf,
594  uncompressed_length, uncompressed,
595  options);
596  if (status == SQUASH_OK) {
597  if (*compressed_length < max_compressed_length) {
598  *compressed_length = max_compressed_length;
599  free (tmp_buf);
601  } else {
602  *compressed_length = max_compressed_length;
603  memcpy (compressed, tmp_buf, max_compressed_length);
604  free (tmp_buf);
605  return SQUASH_OK;
606  }
607  } else {
608  free (tmp_buf);
609  return status;
610  }
611  }
612  } else {
613  SquashStatus status;
614  SquashStream* stream;
615 
617  if (stream == NULL)
618  return squash_error (SQUASH_FAILED);
619 
620  stream->next_in = uncompressed;
621  stream->avail_in = uncompressed_length;
622  stream->next_out = compressed;
623  stream->avail_out = *compressed_length;
624 
625  do {
626  status = squash_stream_process (stream);
627  } while (status == SQUASH_PROCESSING);
628 
629  if (status != SQUASH_OK) {
630  squash_object_unref (stream);
631  return status;
632  }
633 
634  do {
635  status = squash_stream_finish (stream);
636  } while (status == SQUASH_PROCESSING);
637 
638  if (status != SQUASH_OK) {
639  squash_object_unref (stream);
640  return status;
641  }
642 
643  *compressed_length = stream->total_out;
644  squash_object_unref (stream);
645  return status;
646  }
647 }
648 
664  size_t* compressed_length,
665  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
666  size_t uncompressed_length,
667  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
668  ...) {
669  SquashOptions* options;
670  va_list ap;
671 
672  assert (codec != NULL);
673 
674  va_start (ap, uncompressed);
675  options = squash_options_newv (codec, ap);
676  va_end (ap);
677 
679  compressed_length, compressed,
680  uncompressed_length, uncompressed,
681  options);
682 }
683 
699  size_t* decompressed_length,
700  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
701  size_t compressed_length,
702  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
703  SquashOptions* options) {
704  SquashCodecImpl* impl = NULL;
705 
706  assert (codec != NULL);
707 
708  impl = squash_codec_get_impl (codec);
709  if (impl == NULL)
711 
712  if (decompressed == compressed)
714 
715  if (impl->decompress_buffer != NULL) {
716  SquashStatus res;
717  res = impl->decompress_buffer (codec,
718  decompressed_length, decompressed,
719  compressed_length, compressed,
720  squash_object_ref (options));
721  squash_object_unref (options);
722  return res;
723  } else {
724  SquashStatus status;
725  SquashStream* stream;
726 
728  stream->next_in = compressed;
729  stream->avail_in = compressed_length;
730  stream->next_out = decompressed;
731  stream->avail_out = *decompressed_length;
732 
733  do {
734  status = squash_stream_process (stream);
735  } while (status == SQUASH_PROCESSING);
736 
737  if (status == SQUASH_END_OF_STREAM) {
738  status = SQUASH_OK;
739  *decompressed_length = stream->total_out;
740  } else if (status == SQUASH_OK) {
741  do {
742  status = squash_stream_finish (stream);
743  } while (status == SQUASH_PROCESSING);
744 
745  if (status == SQUASH_OK) {
746  *decompressed_length = stream->total_out;
747  }
748  }
749 
750  assert (stream->stream_type == SQUASH_STREAM_DECOMPRESS);
751  squash_object_unref (stream);
752 
753  return status;
754  }
755 }
756 
772 squash_codec_decompress (SquashCodec* codec,
773  size_t* decompressed_length,
774  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
775  size_t compressed_length,
776  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
777  ...) {
778  SquashOptions* options;
779  va_list ap;
780  SquashStatus res;
781 
782  assert (codec != NULL);
783 
784  va_start (ap, compressed);
785  options = squash_options_newv (codec, ap);
786  va_end (ap);
787 
789  decompressed_length, decompressed,
790  compressed_length, compressed,
791  options);
792 
793  return res;
794 }
795 
811 squash_compress (const char* codec,
812  size_t* compressed_length,
813  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
814  size_t uncompressed_length,
815  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
816  ...) {
817  SquashOptions* options;
818  va_list ap;
819  SquashCodec* codec_real = squash_get_codec (codec);
820 
821  if (codec_real == NULL)
823 
824  va_start (ap, uncompressed);
825  options = squash_options_newv (codec_real, ap);
826  va_end (ap);
827 
828  return squash_codec_compress_with_options (codec_real,
829  compressed_length, compressed,
830  uncompressed_length, uncompressed,
831  options);
832 }
833 
848 squash_compress_with_options (const char* codec,
849  size_t* compressed_length,
850  uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)],
851  size_t uncompressed_length,
852  const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],
853  SquashOptions* options) {
854  SquashCodec* codec_real = squash_get_codec (codec);
855 
856  if (codec_real == NULL)
858 
859  return squash_codec_compress_with_options (codec_real,
860  compressed_length, compressed,
861  uncompressed_length, uncompressed,
862  options);
863 }
864 
880 squash_decompress (const char* codec,
881  size_t* decompressed_length,
882  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
883  size_t compressed_length,
884  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
885  ...) {
886  SquashOptions* options;
887  va_list ap;
888  SquashCodec* codec_real = squash_get_codec (codec);
889 
890  if (codec_real == NULL)
892 
893  va_start (ap, compressed);
894  options = squash_options_newv (codec_real, ap);
895  va_end (ap);
896 
897  return squash_codec_decompress_with_options (codec_real,
898  decompressed_length, decompressed,
899  compressed_length, compressed,
900  options);
901 }
902 
917  size_t* decompressed_length,
918  uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],
919  size_t compressed_length,
920  const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],
921  SquashOptions* options) {
922  SquashCodec* codec_real = squash_get_codec (codec);
923 
924  if (codec_real == NULL)
926 
927  return squash_codec_decompress_with_options (codec_real,
928  decompressed_length, decompressed,
929  compressed_length, compressed,
930  options);
931 }
932 
940 SquashCodec*
941 squash_codec_new (SquashPlugin* plugin, const char* name) {
942  SquashCodec* codecp = (SquashCodec*) malloc (sizeof (SquashCodec));
943  SquashCodec codec = { 0, };
944 
945  codec.plugin = plugin;
946  codec.name = strdup (name);
947  codec.priority = 50;
948  SQUASH_TREE_ENTRY_INIT(codec.tree);
949 
950  *codecp = codec;
951 
952  /* squash_plugin_add_codec (plugin, codecp); */
953 
954  return codecp;
955 }
956 
964 void
965 squash_codec_set_extension (SquashCodec* codec, const char* extension) {
966  if (codec->extension != NULL)
967  free (codec->extension);
968 
969  codec->extension = (extension != NULL) ? strdup (extension) : NULL;
970 }
971 
978 const char*
979 squash_codec_get_extension (SquashCodec* codec) {
980  return codec->extension;
981 }
982 
990 void
991 squash_codec_set_priority (SquashCodec* codec, unsigned int priority) {
992  codec->priority = priority;
993 }
994 
1002 squash_codec_get_info (SquashCodec* codec) {
1003  return codec->impl.info;
1004 }
1005 
1014 squash_get_info (const char* codec) {
1015  SquashCodec* codec_real = squash_get_codec (codec);
1016 
1017  if (codec_real != NULL) {
1018  return squash_codec_get_info (codec_real);
1019  } else {
1022  }
1023 }
1024 
1031 const SquashOptionInfo*
1032 squash_codec_get_option_info (SquashCodec* codec) {
1033  SquashCodecImpl* impl = squash_codec_get_impl (codec);
1034  return SQUASH_LIKELY(impl != NULL) ? impl->options : NULL;
1035 }
1036 
1043 const SquashOptionInfo*
1044 squash_get_option_info (const char* codec) {
1045  SquashCodec* codec_real = squash_get_codec (codec);
1046 
1047  if (codec_real != NULL)
1048  return squash_codec_get_option_info (codec_real);
1049  else
1050  return NULL;
1051 }
1052 
1053 static const SquashOptionValue*
1054 squash_codec_get_option_value_by_name (SquashCodec* codec,
1055  SquashOptions* options,
1056  const char* key,
1057  SquashOptionType* type) {
1058  size_t c_option;
1059  const SquashOptionInfo* info;
1060 
1061  assert (codec != NULL);
1062  assert (key != NULL);
1063 
1064  info = squash_codec_get_option_info (codec);
1065  for (c_option = 0 ; info[c_option].name != NULL ; c_option++) {
1066  if (strcasecmp (key, info[c_option].name) == 0) {
1067  if (type != NULL)
1068  *type = info[c_option].type;
1069  return (options != NULL) ?
1070  &(options->values[c_option]) :
1071  &(info[c_option].default_value);
1072  }
1073  }
1074 
1075  if (type != NULL)
1076  *type = SQUASH_OPTION_TYPE_NONE;
1077  return NULL;
1078 }
1079 
1092 const char*
1094  SquashOptions* options,
1095  const char* key) {
1096  SquashOptionType type;
1097  const SquashOptionValue* value = squash_codec_get_option_value_by_name (codec, options, key, &type);
1098  switch ((int) type) {
1099  case SQUASH_OPTION_TYPE_STRING:
1100  return value->string_value;
1101  default:
1102  squash_assert_unreachable();
1103  }
1104 }
1105 
1118 const char*
1120  SquashOptions* options,
1121  size_t index) {
1122  if (options != NULL)
1123  return options->values[index].string_value;
1124  else
1125  return codec->impl.options[index].default_value.string_value;
1126 }
1127 
1140 bool
1141 squash_codec_get_option_bool (SquashCodec* codec,
1142  SquashOptions* options,
1143  const char* key) {
1144  SquashOptionType type;
1145  const SquashOptionValue* value = squash_codec_get_option_value_by_name (codec, options, key, &type);
1146  switch ((int) type) {
1147  case SQUASH_OPTION_TYPE_BOOL:
1148  return value->bool_value;
1149  default:
1150  squash_assert_unreachable();
1151  }
1152 }
1153 
1166 bool
1168  SquashOptions* options,
1169  size_t index) {
1170  if (options != NULL)
1171  return options->values[index].bool_value;
1172  else
1173  return codec->impl.options[index].default_value.bool_value;
1174 }
1175 
1188 int
1189 squash_codec_get_option_int (SquashCodec* codec,
1190  SquashOptions* options,
1191  const char* key) {
1192  SquashOptionType type;
1193  const SquashOptionValue* value = squash_codec_get_option_value_by_name (codec, options, key, &type);
1194  switch ((int) type) {
1195  case SQUASH_OPTION_TYPE_INT:
1196  case SQUASH_OPTION_TYPE_RANGE_INT:
1197  case SQUASH_OPTION_TYPE_ENUM_STRING:
1198  return value->int_value;
1199  default:
1200  squash_assert_unreachable();
1201  }
1202 }
1203 
1216 int
1218  SquashOptions* options,
1219  size_t index) {
1220  if (options != NULL)
1221  return options->values[index].int_value;
1222  else
1223  return codec->impl.options[index].default_value.int_value;
1224 }
1225 
1238 size_t
1239 squash_codec_get_option_size (SquashCodec* codec,
1240  SquashOptions* options,
1241  const char* key) {
1242  SquashOptionType type;
1243  const SquashOptionValue* value = squash_codec_get_option_value_by_name (codec, options, key, &type);
1244  switch ((int) type) {
1245  case SQUASH_OPTION_TYPE_SIZE:
1246  case SQUASH_OPTION_TYPE_RANGE_SIZE:
1247  return value->size_value;
1248  default:
1249  squash_assert_unreachable();
1250  }
1251 }
1252 
1265 size_t
1267  SquashOptions* options,
1268  size_t index) {
1269  if (options != NULL)
1270  return options->values[index].size_value;
1271  else
1272  return codec->impl.options[index].default_value.size_value;
1273 }
1274 
SquashStream * squash_codec_create_stream_with_options(SquashCodec *codec, SquashStreamType stream_type, SquashOptions *options)
Create a new stream with existing SquashOptions.
Definition: codec.c:485
size_t squash_codec_get_option_size(SquashCodec *codec, SquashOptions *options, const char *key)
Get the size value for an option.
Definition: codec.c:1239
size_t squash_get_max_compressed_size(const char *codec, size_t uncompressed_length)
Get the maximum buffer size necessary to store compressed data.
Definition: codec.c:465
bool squash_codec_get_option_bool(SquashCodec *codec, SquashOptions *options, const char *key)
Get the boolean value for an option.
Definition: codec.c:1141
const char * squash_codec_get_option_string_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the string value for an option by index.
Definition: codec.c:1119
SquashStatus squash_stream_finish(SquashStream *stream)
Finish writing to a stream.
Definition: stream.c:743
const SquashOptionInfo * squash_get_option_info(const char *codec)
Get a list of options applicable to the codec.
Definition: codec.c:1044
SquashCodec * squash_get_codec(const char *codec)
Retrieve a SquashCodec.
Definition: context.c:149
SquashCodecInfo squash_get_info(const char *codec)
Get a bitmask of information about the codec.
Definition: codec.c:1014
Operation failed.
Definition: status.h:41
bool squash_codec_get_option_bool_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the boolean value for an option by index.
Definition: codec.c:1167
SquashCodecInfo
Information about the codec.
Definition: codec.h:36
#define SQUASH_CODEC_INFO_INVALID
Invalid codec.
Definition: codec.h:49
SquashStatus squash_decompress(const char *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],...)
Decompress a buffer with an existing SquashOptions.
Definition: codec.c:880
SquashStatus squash_codec_compress(SquashCodec *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],...)
Compress a buffer.
Definition: codec.c:663
A buffer passed to squash was invalid.
Definition: status.h:51
Reached the end of the stream while decoding.
Definition: status.h:39
const char * squash_codec_get_extension(SquashCodec *codec)
Get the codec's extension.
Definition: codec.c:979
SquashPlugin * squash_codec_get_plugin(SquashCodec *codec)
Get the plugin associated with a codec.
Definition: codec.c:324
Operation partially completed.
Definition: status.h:38
A decompression stream.
Definition: stream.h:40
SquashOptions * squash_options_newv(SquashCodec *codec, va_list options)
Create a new group of options from a variadic list.
Definition: options.c:560
The requested codec could not be found.
Definition: status.h:50
size_t squash_codec_get_uncompressed_size(SquashCodec *codec, size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)])
Get the uncompressed size of the compressed buffer.
Definition: codec.c:383
SquashStream * squash_codec_create_stream(SquashCodec *codec, SquashStreamType stream_type,...)
Create a new stream with existing SquashOptions.
Definition: codec.c:517
size_t squash_codec_get_option_size_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the size value for an option by index.
Definition: codec.c:1266
SquashStatus squash_compress_with_options(const char *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)], SquashOptions *options)
Compress a buffer with an existing SquashOptions.
Definition: codec.c:848
SquashStatus squash_codec_init(SquashCodec *codec)
Initialize a codec.
Definition: codec.c:347
SquashCodecImpl * squash_codec_get_impl(SquashCodec *codec)
Get the codec's function table.
Definition: codec.c:358
Insufficient space in buffer.
Definition: status.h:46
SquashStatus squash_compress(const char *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)],...)
Compress a buffer.
Definition: codec.c:811
void * squash_object_unref(void *obj)
Decrement the reference count on an object.
Definition: object.c:255
int squash_codec_get_option_int(SquashCodec *codec, SquashOptions *options, const char *key)
Get the integer value for an option.
Definition: codec.c:1189
size_t squash_codec_get_max_compressed_size(SquashCodec *codec, size_t uncompressed_length)
Get the maximum buffer size necessary to store compressed data.
Definition: codec.c:433
const char * squash_codec_get_name(SquashCodec *codec)
Get the name of a SquashCodec.
Definition: codec.c:298
SquashStatus squash_codec_compress_with_options(SquashCodec *codec, size_t *compressed_length, uint8_t compressed[SQUASH_ARRAY_PARAM(*compressed_length)], size_t uncompressed_length, const uint8_t uncompressed[SQUASH_ARRAY_PARAM(uncompressed_length)], SquashOptions *options)
Compress a buffer with an existing SquashOptions.
Definition: codec.c:545
SquashStatus squash_decompress_with_options(const char *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)], SquashOptions *options)
Decompress a buffer.
Definition: codec.c:916
Not enough memory is available.
Definition: status.h:45
const char * squash_codec_get_option_string(SquashCodec *codec, SquashOptions *options, const char *key)
Get the string value for an option.
Definition: codec.c:1093
SquashStatus squash_codec_decompress_with_options(SquashCodec *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)], SquashOptions *options)
Decompress a buffer with an existing SquashOptions.
Definition: codec.c:698
const SquashOptionInfo * squash_codec_get_option_info(SquashCodec *codec)
Get a list of options applicable to the codec.
Definition: codec.c:1032
SquashStatus
Status codes.
Definition: status.h:36
A compression stream.
Definition: stream.h:39
SquashStatus squash_error(SquashStatus status)
Emit an error.
Definition: status.c:173
SquashStatus squash_codec_decompress(SquashCodec *codec, size_t *decompressed_length, uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)], size_t compressed_length, const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],...)
Decompress a buffer.
Definition: codec.c:772
void * squash_object_ref(void *obj)
Increment the reference count on an object.
Definition: object.c:206
unsigned int squash_codec_get_priority(SquashCodec *codec)
Get the priority of a SquashCodec.
Definition: codec.c:311
SquashStatus squash_stream_process(SquashStream *stream)
Process a stream.
Definition: stream.c:717
SquashCodecInfo squash_codec_get_info(SquashCodec *codec)
Get a bitmask of information about the codec.
Definition: codec.c:1002
Unable to load the requested resource.
Definition: status.h:42
Operation completed successfully.
Definition: status.h:37
int squash_codec_get_option_int_index(SquashCodec *codec, SquashOptions *options, size_t index)
Get the integer value for an option by index.
Definition: codec.c:1217
SquashStreamType
Stream type.
Definition: stream.h:38