⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

loftafi/resources

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resources

This zig module supports loading, searching, and bundling resources into a bundle for distribution.

Example usage

// Load a repository folder of files (with metadata files)
var bucket = try Resources.create(allocator);
defer bucket.destroy();
seed(); // If a uid is generated, make sure it is unique.
_ = 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);

Unicode filenames

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 .

License

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.

About

A minimalist zig module for collecting files into a resource bundle.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages