summaryrefslogtreecommitdiff
path: root/archive.h
blob: 56935d16c54be7b479e88931e2cba2055d2727c5 (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
/*
 * archive.h - tar archive operations for mkpkg
 * https://rawnix.org
 *
 * Copyright (c) 2025 zorz@gmx.com
 * SPDX-License-Identifier: BSD-2-Clause
 */

#ifndef ARCHIVE_H
#define ARCHIVE_H

#include "util.h"

/* detect archive type by file extension */
int arc_is_archive(const char *filename);

/* mkpkg: extract upstream source tarball into destdir, --no-same-owner */
int arc_extract_src(const char *file, const char *destdir);

/* Observe bytes as they are written somewhere (e.g. hash them) */
typedef void (*arc_sink_fn)(const void *buf, size_t len, void *ctx);

/* mkpkg: walk pkgdir, sort entries, pipe to tar | <compressor> -> pkgfile.
 * compression is one of "gz", "xz", "zst", "bz2", "lz" — selects the
 * external compressor program.  NULL or "" means "gz".
 * When sink is non-NULL it is called with every chunk of compressed
 * output as it is written to pkgfile (mkpkg uses this to compute the
 * package SHA256 during the build instead of re-reading the file).
 * Pass NULL/NULL to skip. */
int arc_create_pkg(const char *pkgfile, const char *pkgdir,
                   const char *compression,
                   arc_sink_fn sink, void *sink_ctx);

/* parse pkgfile name and list its contents */
int arc_list(const char *pkgfile, char **name, char **version,
             strarray_t **files);

/* extract package into root, honouring keep/skip lists */
int arc_extract_pkg(const char *pkgfile, const char *root,
                    strarray_t *keep, strarray_t *skip);

/* extract one member of an archive into destdir (quiet).
 * Goes through the same content-sniffed decompressor pipeline as
 * full extraction. */
int arc_extract_single(const char *pkgfile, const char *member,
                       const char *destdir);

/* extract a specific list of members into destdir.
 * tar takes member names as positional arguments, so this unpacks
 * only what was asked for rather than the whole archive. */
int arc_extract_members(const char *pkgfile, strarray_t *members,
                        const char *destdir);

/* print footprint of a package archive to stdout */
int arc_footprint(const char *pkgfile);

#endif /* ARCHIVE_H */