forked from fedora-modularity/libmodulemd
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 665df15
Showing
24 changed files
with
1,713 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
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_DETECTION_FAILED: Autodetection failure | ||
* @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 | ||
* @MODULEMD_COMPRESSION_TYPE_SENTINEL: Enum list terminator | ||
* 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
113 changes: 113 additions & 0 deletions
113
modulemd/include/private/modulemd-compression-private.h
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,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); |
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.