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