dropshell release 2025.0513.2134
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
2
build_arm64/_deps/zstd-src/doc/educational_decoder/.gitignore
vendored
Normal file
2
build_arm64/_deps/zstd-src/doc/educational_decoder/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Build artifacts
|
||||
harness
|
36
build_arm64/_deps/zstd-src/doc/educational_decoder/README.md
Normal file
36
build_arm64/_deps/zstd-src/doc/educational_decoder/README.md
Normal file
@ -0,0 +1,36 @@
|
||||
Educational Decoder
|
||||
===================
|
||||
|
||||
`zstd_decompress.c` is a self-contained implementation in C99 of a decoder,
|
||||
according to the [Zstandard format specification].
|
||||
While it does not implement as many features as the reference decoder,
|
||||
such as the streaming API or content checksums, it is written to be easy to
|
||||
follow and understand, to help understand how the Zstandard format works.
|
||||
It's laid out to match the [format specification],
|
||||
so it can be used to understand how complex segments could be implemented.
|
||||
It also contains implementations of Huffman and FSE table decoding.
|
||||
|
||||
[Zstandard format specification]: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
|
||||
[format specification]: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
|
||||
|
||||
While the library's primary objective is code clarity,
|
||||
it also happens to compile into a small object file.
|
||||
The object file can be made even smaller by removing error messages,
|
||||
using the macro directive `ZDEC_NO_MESSAGE` at compilation time.
|
||||
This can be reduced even further by foregoing dictionary support,
|
||||
by defining `ZDEC_NO_DICTIONARY`.
|
||||
|
||||
`harness.c` provides a simple test harness around the decoder:
|
||||
|
||||
harness <input-file> <output-file> [dictionary]
|
||||
|
||||
As an additional resource to be used with this decoder,
|
||||
see the `decodecorpus` tool in the [tests] directory.
|
||||
It generates valid Zstandard frames that can be used to verify
|
||||
a Zstandard decoder implementation.
|
||||
Note that to use the tool to verify this decoder implementation,
|
||||
the --content-size flag should be set,
|
||||
as this decoder does not handle streaming decoding,
|
||||
and so it must know the decompressed size in advance.
|
||||
|
||||
[tests]: https://github.com/facebook/zstd/blob/dev/tests/
|
119
build_arm64/_deps/zstd-src/doc/educational_decoder/harness.c
Normal file
119
build_arm64/_deps/zstd-src/doc/educational_decoder/harness.c
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under both the BSD-style license (found in the
|
||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||
* in the COPYING file in the root directory of this source tree).
|
||||
* You may select, at your option, one of the above-listed licenses.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "zstd_decompress.h"
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
// If the data doesn't have decompressed size with it, fallback on assuming the
|
||||
// compression ratio is at most 16
|
||||
#define MAX_COMPRESSION_RATIO (16)
|
||||
|
||||
// Protect against allocating too much memory for output
|
||||
#define MAX_OUTPUT_SIZE ((size_t)1024 * 1024 * 1024)
|
||||
|
||||
// Error message then exit
|
||||
#define ERR_OUT(...) { fprintf(stderr, __VA_ARGS__); exit(1); }
|
||||
|
||||
|
||||
typedef struct {
|
||||
u8* address;
|
||||
size_t size;
|
||||
} buffer_s;
|
||||
|
||||
static void freeBuffer(buffer_s b) { free(b.address); }
|
||||
|
||||
static buffer_s read_file(const char *path)
|
||||
{
|
||||
FILE* const f = fopen(path, "rb");
|
||||
if (!f) ERR_OUT("failed to open file %s \n", path);
|
||||
|
||||
fseek(f, 0L, SEEK_END);
|
||||
size_t const size = (size_t)ftell(f);
|
||||
rewind(f);
|
||||
|
||||
void* const ptr = malloc(size);
|
||||
if (!ptr) ERR_OUT("failed to allocate memory to hold %s \n", path);
|
||||
|
||||
size_t const read = fread(ptr, 1, size, f);
|
||||
if (read != size) ERR_OUT("error while reading file %s \n", path);
|
||||
|
||||
fclose(f);
|
||||
buffer_s const b = { ptr, size };
|
||||
return b;
|
||||
}
|
||||
|
||||
static void write_file(const char* path, const u8* ptr, size_t size)
|
||||
{
|
||||
FILE* const f = fopen(path, "wb");
|
||||
if (!f) ERR_OUT("failed to open file %s \n", path);
|
||||
|
||||
size_t written = 0;
|
||||
while (written < size) {
|
||||
written += fwrite(ptr+written, 1, size, f);
|
||||
if (ferror(f)) ERR_OUT("error while writing file %s\n", path);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3)
|
||||
ERR_OUT("usage: %s <file.zst> <out_path> [dictionary] \n", argv[0]);
|
||||
|
||||
buffer_s const input = read_file(argv[1]);
|
||||
|
||||
buffer_s dict = { NULL, 0 };
|
||||
if (argc >= 4) {
|
||||
dict = read_file(argv[3]);
|
||||
}
|
||||
|
||||
size_t out_capacity = ZSTD_get_decompressed_size(input.address, input.size);
|
||||
if (out_capacity == (size_t)-1) {
|
||||
out_capacity = MAX_COMPRESSION_RATIO * input.size;
|
||||
fprintf(stderr, "WARNING: Compressed data does not contain "
|
||||
"decompressed size, going to assume the compression "
|
||||
"ratio is at most %d (decompressed size of at most "
|
||||
"%u) \n",
|
||||
MAX_COMPRESSION_RATIO, (unsigned)out_capacity);
|
||||
}
|
||||
if (out_capacity > MAX_OUTPUT_SIZE)
|
||||
ERR_OUT("Required output size too large for this implementation \n");
|
||||
|
||||
u8* const output = malloc(out_capacity);
|
||||
if (!output) ERR_OUT("failed to allocate memory \n");
|
||||
|
||||
dictionary_t* const parsed_dict = create_dictionary();
|
||||
if (dict.size) {
|
||||
#if defined (ZDEC_NO_DICTIONARY)
|
||||
printf("dict.size = %zu \n", dict.size);
|
||||
ERR_OUT("no dictionary support \n");
|
||||
#else
|
||||
parse_dictionary(parsed_dict, dict.address, dict.size);
|
||||
#endif
|
||||
}
|
||||
size_t const decompressed_size =
|
||||
ZSTD_decompress_with_dict(output, out_capacity,
|
||||
input.address, input.size,
|
||||
parsed_dict);
|
||||
|
||||
free_dictionary(parsed_dict);
|
||||
|
||||
write_file(argv[2], output, decompressed_size);
|
||||
|
||||
freeBuffer(input);
|
||||
freeBuffer(dict);
|
||||
free(output);
|
||||
return 0;
|
||||
}
|
2323
build_arm64/_deps/zstd-src/doc/educational_decoder/zstd_decompress.c
Normal file
2323
build_arm64/_deps/zstd-src/doc/educational_decoder/zstd_decompress.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under both the BSD-style license (found in the
|
||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||
* in the COPYING file in the root directory of this source tree).
|
||||
* You may select, at your option, one of the above-listed licenses.
|
||||
*/
|
||||
|
||||
#include <stddef.h> /* size_t */
|
||||
|
||||
/******* EXPOSED TYPES ********************************************************/
|
||||
/*
|
||||
* Contains the parsed contents of a dictionary
|
||||
* This includes Huffman and FSE tables used for decoding and data on offsets
|
||||
*/
|
||||
typedef struct dictionary_s dictionary_t;
|
||||
/******* END EXPOSED TYPES ****************************************************/
|
||||
|
||||
/******* DECOMPRESSION FUNCTIONS **********************************************/
|
||||
/// Zstandard decompression functions.
|
||||
/// `dst` must point to a space at least as large as the reconstructed output.
|
||||
size_t ZSTD_decompress(void *const dst, const size_t dst_len,
|
||||
const void *const src, const size_t src_len);
|
||||
|
||||
/// If `dict != NULL` and `dict_len >= 8`, does the same thing as
|
||||
/// `ZSTD_decompress` but uses the provided dict
|
||||
size_t ZSTD_decompress_with_dict(void *const dst, const size_t dst_len,
|
||||
const void *const src, const size_t src_len,
|
||||
dictionary_t* parsed_dict);
|
||||
|
||||
/// Get the decompressed size of an input stream so memory can be allocated in
|
||||
/// advance
|
||||
/// Returns -1 if the size can't be determined
|
||||
/// Assumes decompression of a single frame
|
||||
size_t ZSTD_get_decompressed_size(const void *const src, const size_t src_len);
|
||||
/******* END DECOMPRESSION FUNCTIONS ******************************************/
|
||||
|
||||
/******* DICTIONARY MANAGEMENT ***********************************************/
|
||||
/*
|
||||
* Return a valid dictionary_t pointer for use with dictionary initialization
|
||||
* or decompression
|
||||
*/
|
||||
dictionary_t* create_dictionary(void);
|
||||
|
||||
/*
|
||||
* Parse a provided dictionary blob for use in decompression
|
||||
* `src` -- must point to memory space representing the dictionary
|
||||
* `src_len` -- must provide the dictionary size
|
||||
* `dict` -- will contain the parsed contents of the dictionary and
|
||||
* can be used for decompression
|
||||
*/
|
||||
void parse_dictionary(dictionary_t *const dict, const void *src,
|
||||
size_t src_len);
|
||||
|
||||
/*
|
||||
* Free internal Huffman tables, FSE tables, and dictionary content
|
||||
*/
|
||||
void free_dictionary(dictionary_t *const dict);
|
||||
/******* END DICTIONARY MANAGEMENT *******************************************/
|
Reference in New Issue
Block a user