6 n__zip_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_zip.h

Reading members out of a ZIP archive, to a file or into memory. More...

Structures

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

Detailed Description

Reading members out of a ZIP archive, to a file or into memory.

Author: Castagnier Mickael

Version: 1.0

Date: 28/09/2026

What a program needs to take one file out of an archive it downloaded: find the member by name in the central directory, and write it out, stored or deflated, inflated a piece at a time so a member of hundreds of megabytes needs no more memory than its buffers, its CRC-32 checked. Read only; no ZIP64 (a member or an archive over 4 GiB is refused), no encryption, no other compression method.

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __NILOREA_ZIP__
#define __NILOREA_ZIP__

#ifdef __cplusplus
extern "C" {
#endif


#include <stddef.h>
#include <stdint.h>

typedef struct N_ZIP_MEMBER {
    unsigned method;
    uint64_t compressed;
    uint64_t size;
    uint32_t crc;
    uint64_t offset;
} N_ZIP_MEMBER;

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

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

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

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


#ifdef __cplusplus
}
#endif

#endif /* __NILOREA_ZIP__ */