loftafi/resources
A minimalist zig module for collecting files into a resource bundle.
d36cedfcd43071a144dcefd7cadc28ccdc7fa1082c4b3100ccb7aed90ecc9439030899764e2a8d47f5783e87627cbd9e0b45fad112e9f73503914f36518e00df9412df30eea6a1934a7edd2658cdd2d92f02c3b16c073d0bd3d9368a66ce272a574f75a3This zig module supports loading, searching, and bundling resources into a bundle for distribution.
// Load a repository folder of files (with metadata files)
var bucket = try Resources.create(allocator);
defer bucket.destroy();
_ = bucket.load_directory(folder) catch |e| {
std.debug.print("error {any} while loading {s}\n", .{ e, folder });
return Error.FailedReadingRepo;
};
// Load a resource bundle of files.
bucket.load_bundle("/path/to/bundle");
// Search for a resource by filename or word in a filename
var results: std.ArrayListUnmanaged(*Resource) = .empty.
defer results.deinit(allocator);
try bucket.search(keywords.items, .any, &results);
for (results.items) |resource| {
std.debug.print(" {d} {s}\n", .{resource.uid, sentence});
}
// Load a file from the resource bucket
const data = resources.read_data(resource, allocator) catch |e| {
if (e == error.OutOfMemory) return error.OutOfMemory;
if (e == error.FileNotFound) return error.ResourceNotFound;
return error.ResourceReadError;
};
// Save the contents of a list of resources into a bundle
buket.save_bundle("/path/to/bundle", results);
On mac, some files may accidentally become NFD. You can convert all filenames to NFD usinc convmv:
convmv -r -f utf8 -t utf8 --nfc --notest .
This code is released under the terms of the MIT license. This code is useful for my purposes. No warrantee is given or implied that this library will be suitable for your purpose and no warantee is given or implied that this code is free from defects.