1*01826a49SYabin Cui /* 2*01826a49SYabin Cui * Copyright (c) Meta Platforms, Inc. and affiliates. 3*01826a49SYabin Cui * All rights reserved. 4*01826a49SYabin Cui * 5*01826a49SYabin Cui * This source code is licensed under both the BSD-style license (found in the 6*01826a49SYabin Cui * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7*01826a49SYabin Cui * in the COPYING file in the root directory of this source tree). 8*01826a49SYabin Cui * You may select, at your option, one of the above-listed licenses. 9*01826a49SYabin Cui */ 10*01826a49SYabin Cui 11*01826a49SYabin Cui #include <stddef.h> /* size_t */ 12*01826a49SYabin Cui 13*01826a49SYabin Cui /******* EXPOSED TYPES ********************************************************/ 14*01826a49SYabin Cui /* 15*01826a49SYabin Cui * Contains the parsed contents of a dictionary 16*01826a49SYabin Cui * This includes Huffman and FSE tables used for decoding and data on offsets 17*01826a49SYabin Cui */ 18*01826a49SYabin Cui typedef struct dictionary_s dictionary_t; 19*01826a49SYabin Cui /******* END EXPOSED TYPES ****************************************************/ 20*01826a49SYabin Cui 21*01826a49SYabin Cui /******* DECOMPRESSION FUNCTIONS **********************************************/ 22*01826a49SYabin Cui /// Zstandard decompression functions. 23*01826a49SYabin Cui /// `dst` must point to a space at least as large as the reconstructed output. 24*01826a49SYabin Cui size_t ZSTD_decompress(void *const dst, const size_t dst_len, 25*01826a49SYabin Cui const void *const src, const size_t src_len); 26*01826a49SYabin Cui 27*01826a49SYabin Cui /// If `dict != NULL` and `dict_len >= 8`, does the same thing as 28*01826a49SYabin Cui /// `ZSTD_decompress` but uses the provided dict 29*01826a49SYabin Cui size_t ZSTD_decompress_with_dict(void *const dst, const size_t dst_len, 30*01826a49SYabin Cui const void *const src, const size_t src_len, 31*01826a49SYabin Cui dictionary_t* parsed_dict); 32*01826a49SYabin Cui 33*01826a49SYabin Cui /// Get the decompressed size of an input stream so memory can be allocated in 34*01826a49SYabin Cui /// advance 35*01826a49SYabin Cui /// Returns -1 if the size can't be determined 36*01826a49SYabin Cui /// Assumes decompression of a single frame 37*01826a49SYabin Cui size_t ZSTD_get_decompressed_size(const void *const src, const size_t src_len); 38*01826a49SYabin Cui /******* END DECOMPRESSION FUNCTIONS ******************************************/ 39*01826a49SYabin Cui 40*01826a49SYabin Cui /******* DICTIONARY MANAGEMENT ***********************************************/ 41*01826a49SYabin Cui /* 42*01826a49SYabin Cui * Return a valid dictionary_t pointer for use with dictionary initialization 43*01826a49SYabin Cui * or decompression 44*01826a49SYabin Cui */ 45*01826a49SYabin Cui dictionary_t* create_dictionary(void); 46*01826a49SYabin Cui 47*01826a49SYabin Cui /* 48*01826a49SYabin Cui * Parse a provided dictionary blob for use in decompression 49*01826a49SYabin Cui * `src` -- must point to memory space representing the dictionary 50*01826a49SYabin Cui * `src_len` -- must provide the dictionary size 51*01826a49SYabin Cui * `dict` -- will contain the parsed contents of the dictionary and 52*01826a49SYabin Cui * can be used for decompression 53*01826a49SYabin Cui */ 54*01826a49SYabin Cui void parse_dictionary(dictionary_t *const dict, const void *src, 55*01826a49SYabin Cui size_t src_len); 56*01826a49SYabin Cui 57*01826a49SYabin Cui /* 58*01826a49SYabin Cui * Free internal Huffman tables, FSE tables, and dictionary content 59*01826a49SYabin Cui */ 60*01826a49SYabin Cui void free_dictionary(dictionary_t *const dict); 61*01826a49SYabin Cui /******* END DICTIONARY MANAGEMENT *******************************************/ 62