summaryrefslogtreecommitdiff
path: root/firmware/include/zip.h
blob: e58466dff0f222d5df7fa63fcfb0dda35a127170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2021 by James Buren
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#ifndef _ZIP_H_
#define _ZIP_H_

#include <stdbool.h>
#include <stdint.h>
#include <time.h>

enum {
    ZIP_PASS_SHALLOW,
    ZIP_PASS_START,
    ZIP_PASS_DATA,
    ZIP_PASS_END,
};

struct zip;

struct zip_args {
    uint16_t entry;
    uint16_t entries;
    char* name;
    uint32_t file_size;
    time_t modts;
    void* block;
    uint32_t block_size;
    uint32_t read_size;
};

typedef int (*zip_callback) (const struct zip_args* args, int pass, void* ctx);

// open a handle for the given full file name path
struct zip* zip_open(const char* name, bool try_mem);

// quick read of only directory index
int zip_read_shallow(struct zip* z, zip_callback cb, void* ctx);

// slow read of whole archive
// this can also pickup where a successful shallow read leftoff
int zip_read_deep(struct zip* z, zip_callback cb, void* ctx);

// returns system resources
void zip_close(struct zip* z);

#endif