mirror of
https://github.com/pygos/pkg-utils.git
synced 2024-11-06 05:37:10 +01:00
David Oberhollenzer
1205ca0f3b
- Remove compressor registration interface. Doesn't work in a static library, since all the files containing no exported members are optimized away at link time. - Repack as seperate utility library. Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
89 lines
1.7 KiB
C
89 lines
1.7 KiB
C
/* SPDX-License-Identifier: ISC */
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <zlib.h>
|
|
|
|
#include "internal.h"
|
|
|
|
#define CHUNK_SIZE 16384
|
|
|
|
typedef struct {
|
|
compressor_stream_t base;
|
|
uint8_t chunk[CHUNK_SIZE];
|
|
size_t used;
|
|
} dummy_stream_t;
|
|
|
|
static ssize_t dummy_write(compressor_stream_t *base,
|
|
const uint8_t *in, size_t size)
|
|
{
|
|
dummy_stream_t *dummy = (dummy_stream_t *)base;
|
|
|
|
if (size > (CHUNK_SIZE - dummy->used))
|
|
size = CHUNK_SIZE - dummy->used;
|
|
|
|
if (size == 0)
|
|
return 0;
|
|
|
|
memcpy(dummy->chunk + dummy->used, in, size);
|
|
dummy->used += size;
|
|
return size;
|
|
}
|
|
|
|
static ssize_t dummy_read(compressor_stream_t *base,
|
|
uint8_t *out, size_t size)
|
|
{
|
|
dummy_stream_t *dummy = (dummy_stream_t *)base;
|
|
|
|
if (size > dummy->used)
|
|
size = dummy->used;
|
|
|
|
if (size == 0)
|
|
return 0;
|
|
|
|
memcpy(out, dummy->chunk, size);
|
|
|
|
if (size < dummy->used) {
|
|
memmove(dummy->chunk, dummy->chunk + size,
|
|
dummy->used - size);
|
|
}
|
|
|
|
dummy->used -= size;
|
|
return size;
|
|
}
|
|
|
|
static void dummy_flush(compressor_stream_t *base)
|
|
{
|
|
(void)base;
|
|
}
|
|
|
|
static void dummy_destroy(compressor_stream_t *base)
|
|
{
|
|
free(base);
|
|
}
|
|
|
|
static compressor_stream_t *create_dummy_stream(compressor_t *cmp)
|
|
{
|
|
dummy_stream_t *dummy = calloc(1, sizeof(*dummy));
|
|
compressor_stream_t *base;
|
|
(void)cmp;
|
|
|
|
if (dummy == NULL) {
|
|
perror("creating dummy compressor stream");
|
|
return NULL;
|
|
}
|
|
|
|
base = (compressor_stream_t *)dummy;
|
|
base->write = dummy_write;
|
|
base->read = dummy_read;
|
|
base->flush = dummy_flush;
|
|
base->destroy = dummy_destroy;
|
|
return base;
|
|
}
|
|
|
|
compressor_t comp_none = {
|
|
.name = "none",
|
|
.id = PKG_COMPRESSION_NONE,
|
|
.compression_stream = create_dummy_stream,
|
|
.uncompression_stream = create_dummy_stream,
|
|
};
|