libropkg: implement compressed file streams and tar-writer functionality
This commit is contained in:
53
libropkg/include/ropkg/compress.h
Normal file
53
libropkg/include/ropkg/compress.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef ROPKG_COMPRESS_H_
|
||||
#define ROPKG_COMPRESS_H_
|
||||
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct ropkg_compression_function;
|
||||
struct ropkg_compression_stream;
|
||||
|
||||
enum ropkg_compression_stream_mode {
|
||||
ROPKG_COMPRESSION_MODE_COMPRESS = 0,
|
||||
ROPKG_COMPRESSION_MODE_DECOMPRESS,
|
||||
};
|
||||
|
||||
enum ropkg_compression_stream_op {
|
||||
ROPKG_COMPRESSION_OP_CONTINUE = 0,
|
||||
ROPKG_COMPRESSION_OP_END,
|
||||
};
|
||||
|
||||
enum ropkg_compression_type {
|
||||
ROPKG_COMPRESSION_NONE = 0,
|
||||
ROPKG_COMPRESSION_ZSTD,
|
||||
};
|
||||
|
||||
ROPKG_API const struct ropkg_compression_function *
|
||||
ropkg_compression_function_for_type(enum ropkg_compression_type type);
|
||||
|
||||
ROPKG_API 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);
|
||||
ROPKG_API const char *ropkg_compression_function_get_file_extension(
|
||||
const struct ropkg_compression_function *func);
|
||||
|
||||
ROPKG_API 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);
|
||||
ROPKG_API 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);
|
||||
ROPKG_API enum ropkg_status ropkg_compression_stream_close(
|
||||
struct ropkg_compression_stream *stream);
|
||||
|
||||
#endif
|
||||
18
libropkg/include/ropkg/misc.h
Normal file
18
libropkg/include/ropkg/misc.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef ROPKG_MISC_H_
|
||||
#define ROPKG_MISC_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef LIBROPKG_STATIC
|
||||
#define ROPKG_API extern
|
||||
#else
|
||||
#ifdef LIBROPKG_EXPORT
|
||||
#define ROPKG_API extern __declspec(dllexport)
|
||||
#else
|
||||
#define ROPKG_API extern __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define ROPKG_API extern
|
||||
#endif
|
||||
|
||||
#endif
|
||||
14
libropkg/include/ropkg/status.h
Normal file
14
libropkg/include/ropkg/status.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef ROPKG_STATUS_H_
|
||||
#define ROPKG_STATUS_H_
|
||||
|
||||
enum ropkg_status {
|
||||
ROPKG_SUCCESS = 0,
|
||||
ROPKG_ERR_NOT_SUPPORTED,
|
||||
ROPKG_ERR_INVALID_ARGUMENT,
|
||||
ROPKG_ERR_NO_MEMORY,
|
||||
ROPKG_ERR_BAD_STATE,
|
||||
ROPKG_ERR_INTERNAL_FAILURE,
|
||||
ROPKG_ERR_IO_FAILURE,
|
||||
};
|
||||
|
||||
#endif
|
||||
58
libropkg/include/ropkg/stream.h
Normal file
58
libropkg/include/ropkg/stream.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef ROPKG_STREAM_H_
|
||||
#define ROPKG_STREAM_H_
|
||||
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct ropkg_stream;
|
||||
struct ropkg_compression_function;
|
||||
|
||||
enum ropkg_stream_mode {
|
||||
ROPKG_STREAM_READ,
|
||||
ROPKG_STREAM_WRITE,
|
||||
};
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_stream_open(
|
||||
FILE *fp,
|
||||
const struct ropkg_compression_function *func,
|
||||
enum ropkg_stream_mode mode,
|
||||
struct ropkg_stream **out);
|
||||
ROPKG_API enum ropkg_status ropkg_stream_close(struct ropkg_stream *stream);
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_stream_begin_compressed_section(
|
||||
struct ropkg_stream *stream);
|
||||
ROPKG_API enum ropkg_status ropkg_stream_end_compressed_section(
|
||||
struct ropkg_stream *stream,
|
||||
size_t *out_nr_written_compressed,
|
||||
size_t *out_nr_written_uncompressed);
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_stream_read(
|
||||
struct ropkg_stream *stream,
|
||||
void *p,
|
||||
size_t len,
|
||||
size_t *nr_read);
|
||||
ROPKG_API enum ropkg_status ropkg_stream_write(
|
||||
struct ropkg_stream *stream,
|
||||
const void *p,
|
||||
size_t len,
|
||||
size_t *nr_written);
|
||||
|
||||
ROPKG_API size_t ropkg_stream_get_cursor_position(struct ropkg_stream *stream);
|
||||
ROPKG_API enum ropkg_status ropkg_stream_set_cursor_position(
|
||||
struct ropkg_stream *stream,
|
||||
size_t pos);
|
||||
ROPKG_API enum ropkg_status ropkg_stream_restore_cursor_position(
|
||||
struct ropkg_stream *stream);
|
||||
|
||||
ROPKG_API bool ropkg_stream_is_in_compressed_section(
|
||||
struct ropkg_stream *stream);
|
||||
|
||||
ROPKG_API size_t ropkg_stream_get_nr_written(struct ropkg_stream *stream);
|
||||
ROPKG_API size_t
|
||||
ropkg_stream_get_nr_written_compressed(struct ropkg_stream *stream);
|
||||
ROPKG_API size_t
|
||||
ropkg_stream_get_nr_written_uncompressed(struct ropkg_stream *stream);
|
||||
|
||||
#endif
|
||||
36
libropkg/include/ropkg/writer.h
Normal file
36
libropkg/include/ropkg/writer.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef ROPKG_WRITER_H_
|
||||
#define ROPKG_WRITER_H_
|
||||
|
||||
#include <ropkg/misc.h>
|
||||
#include <ropkg/status.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define ROPKG_PATH_DATA "data.tar"
|
||||
#define ROPKG_PATH_CONTROL "control.tar"
|
||||
#define ROPKG_PATH_META "meta.tar"
|
||||
|
||||
struct ropkg_writer;
|
||||
struct ropkg_stream;
|
||||
|
||||
struct ropkg_writer_file_info {
|
||||
size_t f_length;
|
||||
};
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_writer_open(
|
||||
struct ropkg_stream *fp,
|
||||
struct ropkg_writer **out);
|
||||
ROPKG_API enum ropkg_status ropkg_writer_close(struct ropkg_writer *pkg);
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_writer_begin_file(
|
||||
struct ropkg_writer *pkg,
|
||||
const char *path,
|
||||
const struct ropkg_writer_file_info *info);
|
||||
ROPKG_API enum ropkg_status ropkg_writer_end_file(struct ropkg_writer *pkg);
|
||||
|
||||
ROPKG_API enum ropkg_status ropkg_writer_write(
|
||||
struct ropkg_writer *pkg,
|
||||
const void *p,
|
||||
size_t len,
|
||||
size_t *nr_written);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user