2 * Copyright (c) Meta Platforms, Inc. and affiliates.
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
18 data_type_file = 1, /**< This data is a file. *.zst */
19 data_type_dir = 2, /**< This data is a directory. *.tar.zst */
23 char const* url; /**< Where to get this resource. */
24 uint64_t xxhash64; /**< Hash of the url contents. */
25 char const* path; /**< The path of the unpacked resource (derived). */
31 data_type_t type; /**< The type of the data. */
32 char const* name; /**< The logical name of the data (no extension). */
36 * The NULL-terminated list of data objects.
38 extern data_t const* const* data;
41 int data_has_dict(data_t const* data);
44 * Initializes the data module and downloads the data necessary.
45 * Caches the downloads in dir. We add a stamp file in the directory after
46 * a successful download. If a stamp file already exists, and matches our
47 * current data stamp, we will use the cached data without downloading.
49 * @param dir The directory to cache the downloaded data into.
51 * @returns 0 on success.
53 int data_init(char const* dir);
56 * Must be called at exit to free resources allocated by data_init().
58 void data_finish(void);
67 * Read the file that data points to into a buffer.
68 * NOTE: data must be a file, not a directory.
70 * @returns The buffer, which is NULL on failure.
72 data_buffer_t data_buffer_get_data(data_t const* data);
75 * Read the dictionary that the data points to into a buffer.
77 * @returns The buffer, which is NULL on failure.
79 data_buffer_t data_buffer_get_dict(data_t const* data);
82 * Read the contents of filename into a buffer.
84 * @returns The buffer, which is NULL on failure.
86 data_buffer_t data_buffer_read(char const* filename);
89 * Create a buffer with the specified capacity.
91 * @returns The buffer, which is NULL on failure.
93 data_buffer_t data_buffer_create(size_t capacity);
96 * Calls memcmp() on the contents [0, size) of both buffers.
98 int data_buffer_compare(data_buffer_t buffer1, data_buffer_t buffer2);
101 * Frees an allocated buffer.
103 void data_buffer_free(data_buffer_t buffer);
107 data_buffer_t const* buffers;
112 * @returns a list of buffers for every file in data. It is zero sized on error.
114 data_buffers_t data_buffers_get(data_t const* data);
117 * Frees the data buffers.
119 void data_buffers_free(data_buffers_t buffers);