mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Extend GetZipPaths to accept an optional prefix (#320)
This commit is contained in:
parent
7fe9e70117
commit
8f05990d5a
2 changed files with 9 additions and 5 deletions
|
@ -746,9 +746,10 @@ FUNCTIONS
|
|||
minor (mm), and patch (pp) versions encoded. The version value 1.4
|
||||
would be represented as 0x010400.
|
||||
|
||||
GetZipPaths() → {path:str,...}
|
||||
GetZipPaths([prefix:str]) → {path:str,...}
|
||||
Returns paths of all assets in the zip central directory, prefixed
|
||||
by a slash.
|
||||
by a slash. If prefix parameter is provided, then only paths that
|
||||
start with the prefix (case sensitive) are returned.
|
||||
|
||||
HasParam(name:str) → bool
|
||||
Returns true if parameter with name was supplied in either the
|
||||
|
|
|
@ -5014,7 +5014,8 @@ static int LuaIsHiddenPath(lua_State *L) {
|
|||
static int LuaGetZipPaths(lua_State *L) {
|
||||
char *path;
|
||||
uint8_t *zcf;
|
||||
size_t i, n, pathlen;
|
||||
size_t i, n, pathlen, prefixlen;
|
||||
char *prefix = luaL_optlstring(L, 1, "", &prefixlen);
|
||||
lua_newtable(L);
|
||||
i = 0;
|
||||
n = GetZipCdirRecords(zcdir);
|
||||
|
@ -5022,8 +5023,10 @@ static int LuaGetZipPaths(lua_State *L) {
|
|||
zcf += ZIP_CFILE_HDRSIZE(zcf)) {
|
||||
CHECK_EQ(kZipCfileHdrMagic, ZIP_CFILE_MAGIC(zcf));
|
||||
path = GetAssetPath(zcf, &pathlen);
|
||||
if (prefixlen == 0 || startswith(path, prefix)) {
|
||||
lua_pushlstring(L, path, pathlen);
|
||||
lua_seti(L, -2, ++i);
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue