libropkg: implement compressed file streams and tar-writer functionality
This commit is contained in:
86
libropkg/compress.c
Normal file
86
libropkg/compress.c
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "compress.h"
|
||||
|
||||
#include <ropkg/compress.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern const struct ropkg_compression_function ropkg_zstd;
|
||||
|
||||
static const struct ropkg_compression_function *functions[] = {
|
||||
[ROPKG_COMPRESSION_ZSTD] = &ropkg_zstd,
|
||||
};
|
||||
static const size_t nr_functions = sizeof functions / sizeof functions[0];
|
||||
|
||||
const struct ropkg_compression_function *ropkg_compression_function_for_type(
|
||||
enum ropkg_compression_type type)
|
||||
{
|
||||
if (type >= nr_functions) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return functions[type];
|
||||
}
|
||||
|
||||
enum ropkg_status ropkg_compression_function_get_buffer_size(
|
||||
const struct ropkg_compression_function *func,
|
||||
enum ropkg_compression_stream_mode mode,
|
||||
size_t *in_buffer_size,
|
||||
size_t *out_buffer_size)
|
||||
{
|
||||
if (!func->f_buffer_size) {
|
||||
return ROPKG_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return func->f_buffer_size(mode, in_buffer_size, out_buffer_size);
|
||||
}
|
||||
|
||||
const char *ropkg_compression_function_get_file_extension(
|
||||
const struct ropkg_compression_function *func)
|
||||
{
|
||||
return func->f_extension;
|
||||
}
|
||||
|
||||
enum ropkg_status ropkg_compression_stream_open(
|
||||
const struct ropkg_compression_function *func,
|
||||
void *in_buffer,
|
||||
size_t in_max,
|
||||
void *out_buffer,
|
||||
size_t out_max,
|
||||
enum ropkg_compression_stream_mode mode,
|
||||
struct ropkg_compression_stream **out)
|
||||
{
|
||||
if (!func->f_open) {
|
||||
return ROPKG_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return func->f_open(
|
||||
func,
|
||||
mode,
|
||||
in_buffer,
|
||||
in_max,
|
||||
out_buffer,
|
||||
out_max,
|
||||
out);
|
||||
}
|
||||
|
||||
enum ropkg_status ropkg_compression_stream_process(
|
||||
struct ropkg_compression_stream *stream,
|
||||
size_t in_size,
|
||||
enum ropkg_compression_stream_op op,
|
||||
size_t *out_size)
|
||||
{
|
||||
if (!stream->s_func->f_process) {
|
||||
return ROPKG_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return stream->s_func->f_process(stream, in_size, op, out_size);
|
||||
}
|
||||
|
||||
enum ropkg_status ropkg_compression_stream_close(
|
||||
struct ropkg_compression_stream *stream)
|
||||
{
|
||||
if (!stream->s_func->f_close) {
|
||||
return ROPKG_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return stream->s_func->f_close(stream);
|
||||
}
|
||||
Reference in New Issue
Block a user