![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Reading members out of a ZIP archive, to a file. More...
#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <string.h>#include <zlib.h>#include "nilorea/n_log.h"#include "nilorea/n_zip.h"Go to the source code of this file.
Data Structures | |
| struct | ZIP_SINK |
| where unpacked bytes go: a file, or a buffer in memory More... | |
Macros | |
| #define | N_ZIP_CHUNK 262144 |
| the pieces a member is read and written in | |
| #define | N_ZIP_TAIL (22 + 65535) |
| how much of an archive's end is searched for its end record: the record and the longest comment it may carry | |
Functions | |
| static unsigned | le16 (const unsigned char *p) |
| helper: a little endian 16 bit value | |
| static uint32_t | le32 (const unsigned char *p) |
| helper: a little endian 32 bit value | |
| 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 | |
| static int | seek_to (FILE *f, uint64_t at) |
| helper: seek to a 64 bit offset where the platform's fseek takes a long | |
| static int | sink_put (ZIP_SINK *sink, const unsigned char *data, size_t len) |
| put unpacked bytes where they go | |
| static int | zip_scan (const char *path, const char *name, int ending, N_ZIP_MEMBER *member, char *found_name, size_t found_len) |
| find a member by its whole name, or by how its name ends | |
| static int | zip_unpack (const char *path, const char *name, const N_ZIP_MEMBER *member, ZIP_SINK *sink) |
| unpack a member into a sink, checking its size and CRC-32 | |
Reading members out of a ZIP archive, to a file.
Definition in file n_zip.c.
| struct ZIP_SINK |
| #define N_ZIP_CHUNK 262144 |
the pieces a member is read and written in
Definition at line 42 of file n_zip.c.
Referenced by zip_unpack().
| #define N_ZIP_TAIL (22 + 65535) |
how much of an archive's end is searched for its end record: the record and the longest comment it may carry
Definition at line 40 of file n_zip.c.
Referenced by zip_scan().
|
static |
helper: a little endian 16 bit value
Definition at line 45 of file n_zip.c.
Referenced by zip_scan(), and zip_unpack().
|
static |
helper: a little endian 32 bit value
Definition at line 49 of file n_zip.c.
Referenced by make_tiff(), make_webp(), zip_scan(), and zip_unpack().
|
static |
helper: seek to a 64 bit offset where the platform's fseek takes a long
Definition at line 54 of file n_zip.c.
Referenced by zip_scan(), and zip_unpack().
|
static |
put unpacked bytes where they go
| sink | the destination |
| data | the bytes |
| len | how many |
Definition at line 178 of file n_zip.c.
References ZIP_SINK::buffer, ZIP_SINK::file, ZIP_SINK::size, and ZIP_SINK::used.
Referenced by zip_unpack().
|
static |
find a member by its whole name, or by how its name ends
| path | the archive |
| name | the name, or its ending |
| ending | non-zero to match the ending only |
| member | receives what it is, may be NULL |
| found_name | receives the whole name when matching an ending, may be NULL |
| found_len | size of found_name |
Definition at line 67 of file n_zip.c.
References N_ZIP_MEMBER::compressed, N_ZIP_MEMBER::crc, le16(), le32(), LOG_ERR, N_ZIP_MEMBER::method, n_log, N_ZIP_TAIL, N_ZIP_MEMBER::offset, seek_to(), and N_ZIP_MEMBER::size.
Referenced by n_zip_find(), and n_zip_find_ending().
|
static |
unpack a member into a sink, checking its size and CRC-32
| path | the archive |
| name | the member |
| member | what n_zip_find() said of it |
| sink | where the bytes go |
Definition at line 192 of file n_zip.c.
References N_ZIP_MEMBER::compressed, N_ZIP_MEMBER::crc, done, le16(), le32(), LOG_ERR, N_ZIP_MEMBER::method, n_log, N_ZIP_CHUNK, N_ZIP_MEMBER::offset, seek_to(), sink_put(), and N_ZIP_MEMBER::size.
Referenced by n_zip_extract(), and n_zip_read().