Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ZIP: reading members out of an archive

Data Structures

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

Functions

int n_zip_extract (const char *path, const char *name, const char *out)
 write a member out to a file, checking its CRC-32
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_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_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

Detailed Description


Data Structure Documentation

◆ N_ZIP_MEMBER

struct N_ZIP_MEMBER

What n_zip_find() says about a member.

Examples
ex_zip.c.

Definition at line 52 of file n_zip.h.

Collaboration diagram for N_ZIP_MEMBER:
Data Fields
uint64_t compressed its size in the archive
uint32_t crc its CRC-32
unsigned method 0 stored, 8 deflated
uint64_t offset where its local header is
uint64_t size its size once out

Function Documentation

◆ 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
paththe archive
namethe member's name as stored
outthe file to write; replaced, and removed again on any failure
Returns
0, or -1 when the member is not there, is compressed another way, or its data or CRC-32 is wrong

Definition at line 267 of file n_zip.c.

References ZIP_SINK::file, n_zip_find(), and zip_unpack().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this 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
paththe archive
namethe member's name as stored, "dir/file.ext"
memberreceives what it is, may be NULL
Returns
0 when found, -1 when not, or when the archive cannot be read

Definition at line 152 of file n_zip.c.

References zip_scan().

Referenced by main(), n_zip_extract(), and n_zip_read().

Here is the call graph for this function:
Here is the caller graph for this 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
paththe archive
endinghow the name ends
namereceives the member's whole name
name_lensize of name
Returns
0 when found, -1 when not, or when the archive cannot be read

Definition at line 156 of file n_zip.c.

References zip_scan().

Referenced by main(), and n_pth_load().

Here is the call graph for this function:
Here is the caller graph for this 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
paththe archive
namethe member's name as stored
max_sizethe largest member accepted, a guard against an archive that claims gigabytes
datareceives the bytes, allocated with malloc() and ended by one zero byte past len; freed by the caller with free(); NULL on failure
lenreceives how many
Returns
0, or -1 when the member is not there, too large, compressed another way, or its data or CRC-32 is wrong

Definition at line 282 of file n_zip.c.

References ZIP_SINK::buffer, LOG_ERR, n_log, n_zip_find(), N_ZIP_MEMBER::size, ZIP_SINK::size, ZIP_SINK::used, and zip_unpack().

Referenced by main(), n_pth_load(), and tensor_read().

Here is the call graph for this function:
Here is the caller graph for this function: