forked from fedora-modularity/libmodulemd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helpers for reading compressed files
Currently supports gzip, bzip2 and xz compression formats. Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
- Loading branch information
1 parent
4f2fe62
commit f19fb8f
Showing
21 changed files
with
1,677 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* This file is part of libmodulemd | ||
* Copyright (C) 2019 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> | ||
|
||
G_BEGIN_DECLS | ||
|
||
/** | ||
* SECTION: modulemd-compression | ||
* @title: Modulemd Compression Helpers | ||
* @stability: stable | ||
* @short_description: Utility functions for working with compressed files. | ||
*/ | ||
|
||
|
||
/** | ||
* ModulemdCompressionTypeEnum | ||
* @MODULEMD_COMPRESSION_TYPE_AUTO_DETECT_COMPRESSION: Autodetection | ||
* @MODULEMD_COMPRESSION_TYPE_UNKNOWN_COMPRESSION: Unknown compression | ||
* @MODULEMD_COMPRESSION_TYPE_NO_COMPRESSION: No compression | ||
* @MODULEMD_COMPRESSION_TYPE_GZ_COMPRESSION: gzip compression | ||
* @MODULEMD_COMPRESSION_TYPE_BZ2_COMPRESSION: bzip2 compression | ||
* @MODULEMD_COMPRESSION_TYPE_XZ_COMPRESSION: LZMA compression | ||
* @MODULEMD_COMPRESSION_TYPE_ZCK_COMPRESSION: zchunk compression | ||
* | ||
* Since: 2.8 | ||
*/ | ||
typedef enum | ||
{ | ||
MODULEMD_COMPRESSION_TYPE_DETECTION_FAILED = -2, | ||
MODULEMD_COMPRESSION_TYPE_UNKNOWN_COMPRESSION, | ||
MODULEMD_COMPRESSION_TYPE_NO_COMPRESSION, | ||
MODULEMD_COMPRESSION_TYPE_GZ_COMPRESSION, | ||
MODULEMD_COMPRESSION_TYPE_BZ2_COMPRESSION, | ||
MODULEMD_COMPRESSION_TYPE_XZ_COMPRESSION, | ||
MODULEMD_COMPRESSION_TYPE_ZCK_COMPRESSION, | ||
MODULEMD_COMPRESSION_TYPE_SENTINEL, | ||
} ModulemdCompressionTypeEnum; | ||
|
||
|
||
/** | ||
* modulemd_compression_type: | ||
* @name: (in): The name of the compression type. Valid options are: | ||
* "gz", "gzip", "bz2", "bzip2", "xz" and "zck". | ||
* | ||
* Returns: The #ModulemdCompressionTypeEnum value corresponding to the | ||
* provided string if available or | ||
* #MODULEMD_COMPRESSION_TYPE_UNKNOWN_COMPRESSION if the string does not match | ||
* a known type. | ||
* | ||
* Since: 2.8 | ||
*/ | ||
ModulemdCompressionTypeEnum | ||
modulemd_compression_type (const gchar *name); | ||
|
||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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> | ||
void | ||
mmd_Fclose (FD_t fd); | ||
G_DEFINE_AUTO_CLEANUP_FREE_FUNC (FD_t, mmd_Fclose, NULL); | ||
#endif | ||
|
||
/** | ||
* SECTION: modulemd-compression-private | ||
* @title: Modulemd Compression Helpers (Private) | ||
* @stability: Private | ||
* @short_description: Internal utility functions for working with compressed | ||
* files. | ||
*/ | ||
|
||
|
||
/** | ||
* 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: | ||
* | ||
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.