5 Module N_ZIP
gullradriel edited this page 2026-10-09 00:55:18 +02:00

ZIP: reading members out of an archive

Structures

Name
struct N_ZIP_MEMBER
What n_zip_find() says about a member.

Functions

Name
int n_zip_read(const char * path, const char * name, size_t max_size, unsigned char ** data, size_t * len)
read a member into memory, checking its CRC-32
int n_zip_find_ending(const char * path, const char * ending, char * name, size_t name_len)
find the first member whose name ends with a given text, as a PyTorch checkpoint's "archive/data.pkl" whose folder name varies
int n_zip_find(const char * path, const char * name, N_ZIP_MEMBER * member)
find a member by its full name in an archive's central directory
int n_zip_extract(const char * path, const char * name, const char * out)
write a member out to a file, checking its CRC-32

Functions Documentation

function n_zip_read

int n_zip_read(
    const char * path,
    const char * name,
    size_t max_size,
    unsigned char ** data,
    size_t * len
)

read a member into memory, checking its CRC-32

Parameters:

  • path the archive
  • name the member's name as stored
  • max_size the largest member accepted, a guard against an archive that claims gigabytes
  • data receives the bytes, allocated with malloc() and ended by one zero byte past len; freed by the caller with free(); NULL on failure
  • len receives how many

Return: 0, or -1 when the member is not there, too large, compressed another way, or its data or CRC-32 is wrong

function n_zip_find_ending

int n_zip_find_ending(
    const char * path,
    const char * ending,
    char * name,
    size_t name_len
)

find the first member whose name ends with a given text, as a PyTorch checkpoint's "archive/data.pkl" whose folder name varies

Parameters:

  • path the archive
  • ending how the name ends
  • name receives the member's whole name
  • name_len size of name

Return: 0 when found, -1 when not, or when the archive cannot be read

function n_zip_find

int n_zip_find(
    const char * path,
    const char * name,
    N_ZIP_MEMBER * member
)

find a member by its full name in an archive's central directory

Parameters:

  • path the archive
  • name the member's name as stored, "dir/file.ext"
  • member receives what it is, may be NULL

Return: 0 when found, -1 when not, or when the archive cannot be read

function n_zip_extract

int n_zip_extract(
    const char * path,
    const char * name,
    const char * out
)

write a member out to a file, checking its CRC-32

Parameters:

  • path the archive
  • name the member's name as stored
  • out the file to write; replaced, and removed again on any failure

Return: 0, or -1 when the member is not there, is compressed another way, or its data or CRC-32 is wrong