loftafi/resources
A minimalist zig module for collecting files into a resource bundle.
5bf17dcb0be38c2e8893497fd7705a8aac89faab
a70604a93988ee553d0ae6a3871726270a6025d5
v0.14.1.tar.gz
70a3abe922d65ec13b488b0890970edcf11e0006
518e00df9412df30eea6a1934a7edd2658cdd2d9
This 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.