loftafi/resources
A minimalist zig module for collecting files into a resource bundle.
e839acbeada56e56965d9a69dbc5f8db4c4d5e6d
a70604a93988ee553d0ae6a3871726270a6025d5
v0.14.1.tar.gz
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);
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.