File: modulemd-compression-private.h

package info (click to toggle)
libmodulemd 2.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,180 kB
  • sloc: ansic: 37,927; python: 3,233; xml: 1,739; sh: 389; makefile: 42
file content (113 lines) | stat: -rw-r--r-- 3,040 bytes parent folder | download | duplicates (4)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * This file is part of libmodulemd
 * Copyright (C) 2018 Red Hat, Inc.
 *
 * Fedora-License-Identifier: MIT
 * SPDX-2.0-License-Identifier: MIT
 * SPDX-3.0-License-Identifier: MIT
 *
 * This program is free software.
 * For more information on the license, see COPYING.
 * For more information on free software, see <https://www.gnu.org/philosophy/free-sw.en.html>.
 */

#pragma once

#include <glib.h>

#include "config.h"
#include "modulemd-compression.h"

#ifdef HAVE_RPMIO
#include <rpm/rpmio.h>
#endif

/**
 * SECTION: modulemd-compression-private
 * @title: Modulemd Compression Helpers (Private)
 * @stability: Private
 * @short_description: Internal utility functions for working with compressed
 * files.
 */


#ifdef HAVE_RPMIO
/**
 * mmd_Fclose:
 * @fd: (in): A FD_t from rpmio.h to be closed
 *
 * Wrapper for rpmio's Fclose() function to use with
 * #G_DEFINE_AUTO_CLEANUP_FREE_FUNC()
 *
 * Since: 2.8
 */
void
mmd_Fclose (FD_t fd);

G_DEFINE_AUTO_CLEANUP_FREE_FUNC (FD_t, mmd_Fclose, NULL);
#endif


/**
 * modulemd_detect_compression:
 * @filename: (in): The original filename that matches @fd.
 * @fd: (in): An open file descriptor pointing at a real file.
 * @error: (out): A #GError containing the reason this function failed.
 *
 * Returns: The #ModulemdCompressionTypeEnum detected from this file
 * descriptor. In the event of an error, returns
 * #MODULEMD_COMPRESSION_TYPE_DETECTION_FAILED and sets @error
 * appropriately. Returns #MODULEMD_COMPRESSION_TYPE_UNKNOWN_COMPRESSION if
 * all detection methods complete but the type is still indeterminate.
 *
 * Since: 2.8
 */
ModulemdCompressionTypeEnum
modulemd_detect_compression (const gchar *filename, int fd, GError **error);


/**
 * modulemd_compression_suffix:
 * @comtype: (in): A #ModulemdCompressionTypeEnum.
 *
 * Returns: (transfer none): A static string representing the filename suffix
 * that a file of this compression type should have.
 *
 * Since: 2.8
 */
const gchar *
modulemd_compression_suffix (ModulemdCompressionTypeEnum comtype);


/**
 * modulemd_get_rpmio_fmode:
 * @mode: (in): A mode argument that will be passed to `fopen(3)`.
 * @comtype: (in): A #ModulemdCompressionTypeEnum.
 *
 * Returns: (transfer full): A string suitable for passing to rpmio's
 * `Fopen()` function. NULL if @mode is NULL or the @comtype is invalid.
 *
 * Since: 2.8
 */
gchar *
modulemd_get_rpmio_fmode (const gchar *mode,
                          ModulemdCompressionTypeEnum comtype);


/**
 * compressed_stream_read_fn:
 * @data: (inout): A private pointer to the data being read.
 * @buffer: (out): The buffer to write the data from the source.
 * @size: (in): The size of the buffer.
 * @size_read: (out): The actual number of bytes read from the source.
 *
 * A #ModulemdReadHandler that uses rpmio's `Fread()` function to handle
 * compressed files.
 *
 * Since: 2.8
 */
gint
compressed_stream_read_fn (void *data,
                           unsigned char *buffer,
                           size_t size,
                           size_t *size_read);