meta: rename to fx
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <fx/compress/compressor.h>
|
||||
#include <fx/compress/cstream.h>
|
||||
#include <fx/compress/zstd.h>
|
||||
#include <fx/core/ringbuffer.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -26,7 +26,7 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_mode mode = B_COMPRESSOR_MODE_COMPRESS;
|
||||
fx_compressor_mode mode = FX_COMPRESSOR_MODE_COMPRESS;
|
||||
|
||||
FILE *out_fp = fopen(argv[1], "wb");
|
||||
if (!out_fp) {
|
||||
@@ -34,36 +34,36 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_stream *out_stream = b_stream_open_fp(out_fp);
|
||||
b_cstream *cstream;
|
||||
b_cstream_open(out_stream, B_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
|
||||
fx_stream *out_stream = fx_stream_open_fp(out_fp);
|
||||
fx_cstream *cstream;
|
||||
fx_cstream_open(out_stream, FX_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
|
||||
|
||||
const size_t source_len = strlen(source);
|
||||
bool compressed = false;
|
||||
|
||||
for (int i = 0; i < NR_ITERATIONS; i++) {
|
||||
if (compressed) {
|
||||
b_cstream_begin_compressed_section(cstream, NULL);
|
||||
fx_cstream_begin_compressed_section(cstream, NULL);
|
||||
}
|
||||
|
||||
size_t nr_written = 0;
|
||||
b_status status = b_cstream_write(
|
||||
fx_status status = fx_cstream_write(
|
||||
cstream, source, source_len, &nr_written);
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
fprintf(stderr, "write error: %s\n",
|
||||
b_status_description(status));
|
||||
fx_status_description(status));
|
||||
break;
|
||||
}
|
||||
|
||||
size_t nr_written_compressed = 0;
|
||||
|
||||
if (compressed) {
|
||||
b_cstream_end_compressed_section(
|
||||
fx_cstream_end_compressed_section(
|
||||
cstream, &nr_written_compressed, &nr_written);
|
||||
}
|
||||
|
||||
size_t tx_total = 0;
|
||||
b_cstream_tx_bytes(cstream, &tx_total);
|
||||
fx_cstream_tx_bytes(cstream, &tx_total);
|
||||
printf("iteration %d: wrote %zu (compressed) / %zu "
|
||||
"(uncompressed) / %zu (total) bytes (%s)\n",
|
||||
i, nr_written_compressed, nr_written, tx_total,
|
||||
@@ -74,8 +74,8 @@ int main(int argc, const char **argv)
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(out_stream);
|
||||
fx_cstream_unref(cstream);
|
||||
fx_stream_unref(out_stream);
|
||||
fclose(out_fp);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <fx/compress/compressor.h>
|
||||
#include <fx/compress/cstream.h>
|
||||
#include <fx/compress/zstd.h>
|
||||
#include <fx/core/ringbuffer.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -14,7 +14,7 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_mode mode = B_COMPRESSOR_MODE_DECOMPRESS;
|
||||
fx_compressor_mode mode = FX_COMPRESSOR_MODE_DECOMPRESS;
|
||||
|
||||
FILE *in_fp = fopen(argv[1], "rb");
|
||||
if (!in_fp) {
|
||||
@@ -22,26 +22,26 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_stream *in_stream = b_stream_open_fp(in_fp);
|
||||
b_cstream *cstream;
|
||||
b_cstream_open(in_stream, B_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
|
||||
fx_stream *in_stream = fx_stream_open_fp(in_fp);
|
||||
fx_cstream *cstream;
|
||||
fx_cstream_open(in_stream, FX_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
|
||||
|
||||
bool compressed = false;
|
||||
char buf[513];
|
||||
|
||||
for (int i = 0;; i++) {
|
||||
if (compressed) {
|
||||
b_cstream_begin_compressed_section(cstream, NULL);
|
||||
fx_cstream_begin_compressed_section(cstream, NULL);
|
||||
}
|
||||
|
||||
memset(buf, 0x0, sizeof buf);
|
||||
|
||||
size_t nr_read = 0;
|
||||
b_status status
|
||||
= b_cstream_read(cstream, buf, sizeof buf - 1, &nr_read);
|
||||
if (!B_OK(status)) {
|
||||
fx_status status
|
||||
= fx_cstream_read(cstream, buf, sizeof buf - 1, &nr_read);
|
||||
if (!FX_OK(status)) {
|
||||
fprintf(stderr, "write error: %s\n",
|
||||
b_status_description(status));
|
||||
fx_status_description(status));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -51,12 +51,12 @@ int main(int argc, const char **argv)
|
||||
|
||||
size_t nr_read_compressed = 0;
|
||||
if (compressed) {
|
||||
b_cstream_end_compressed_section(
|
||||
fx_cstream_end_compressed_section(
|
||||
cstream, &nr_read_compressed, &nr_read);
|
||||
}
|
||||
|
||||
size_t tx_total = 0;
|
||||
b_cstream_tx_bytes(cstream, &tx_total);
|
||||
fx_cstream_tx_bytes(cstream, &tx_total);
|
||||
printf(" * iteration %d: read %zu (compressed) / %zu "
|
||||
"(uncompressed) / %zu (total) bytes (%s)\n",
|
||||
i, nr_read_compressed, nr_read, tx_total,
|
||||
@@ -68,8 +68,8 @@ int main(int argc, const char **argv)
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(in_stream);
|
||||
fx_cstream_unref(cstream);
|
||||
fx_stream_unref(in_stream);
|
||||
fclose(in_fp);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <fx/compress/compressor.h>
|
||||
#include <fx/compress/zstd.h>
|
||||
#include <fx/core/ringbuffer.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUF_SIZE 32
|
||||
|
||||
int refill_input_buffer(FILE *fp, b_ringbuffer *dest)
|
||||
int refill_input_buffer(FILE *fp, fx_ringbuffer *dest)
|
||||
{
|
||||
while (1) {
|
||||
void *buf;
|
||||
size_t capacity;
|
||||
b_status status
|
||||
= b_ringbuffer_open_write_buffer(dest, &buf, &capacity);
|
||||
if (status == B_ERR_NO_SPACE) {
|
||||
fx_status status
|
||||
= fx_ringbuffer_open_write_buffer(dest, &buf, &capacity);
|
||||
if (status == FX_ERR_NO_SPACE) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t r = fread(buf, 1, capacity, fp);
|
||||
|
||||
b_ringbuffer_close_write_buffer(dest, &buf, r);
|
||||
fx_ringbuffer_close_write_buffer(dest, &buf, r);
|
||||
|
||||
if (r == 0) {
|
||||
return ferror(fp) ? -1 : 0;
|
||||
@@ -38,24 +38,24 @@ int refill_input_buffer(FILE *fp, b_ringbuffer *dest)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flush_output_buffer(FILE *fp, b_ringbuffer *src)
|
||||
int flush_output_buffer(FILE *fp, fx_ringbuffer *src)
|
||||
{
|
||||
while (1) {
|
||||
const void *buf;
|
||||
size_t capacity;
|
||||
b_status status
|
||||
= b_ringbuffer_open_read_buffer(src, &buf, &capacity);
|
||||
if (status == B_ERR_NO_DATA) {
|
||||
fx_status status
|
||||
= fx_ringbuffer_open_read_buffer(src, &buf, &capacity);
|
||||
if (status == FX_ERR_NO_DATA) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t w = fwrite(buf, 1, capacity, fp);
|
||||
|
||||
b_ringbuffer_close_read_buffer(src, &buf, w);
|
||||
fx_ringbuffer_close_read_buffer(src, &buf, w);
|
||||
|
||||
if (w < capacity) {
|
||||
return -1;
|
||||
@@ -72,11 +72,11 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_mode mode;
|
||||
fx_compressor_mode mode;
|
||||
if (!strcmp(argv[1], "C")) {
|
||||
mode = B_COMPRESSOR_MODE_COMPRESS;
|
||||
mode = FX_COMPRESSOR_MODE_COMPRESS;
|
||||
} else if (!strcmp(argv[1], "D")) {
|
||||
mode = B_COMPRESSOR_MODE_DECOMPRESS;
|
||||
mode = FX_COMPRESSOR_MODE_DECOMPRESS;
|
||||
} else {
|
||||
fprintf(stderr, "invalid mode %s\n", argv[1]);
|
||||
return -1;
|
||||
@@ -95,24 +95,24 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_status status = B_SUCCESS;
|
||||
b_type compressor_type = B_TYPE_ZSTD_COMPRESSOR;
|
||||
b_compressor *compressor = b_object_create(compressor_type);
|
||||
fx_status status = FX_SUCCESS;
|
||||
fx_type compressor_type = FX_TYPE_ZSTD_COMPRESSOR;
|
||||
fx_compressor *compressor = fx_object_create(compressor_type);
|
||||
|
||||
size_t inbuf_size, outbuf_size;
|
||||
b_compressor_get_buffer_size(
|
||||
fx_compressor_get_buffer_size(
|
||||
compressor_type, mode, &inbuf_size, &outbuf_size);
|
||||
|
||||
b_ringbuffer *in = b_ringbuffer_create(inbuf_size);
|
||||
b_ringbuffer *out = b_ringbuffer_create(outbuf_size);
|
||||
fx_ringbuffer *in = fx_ringbuffer_create(inbuf_size);
|
||||
fx_ringbuffer *out = fx_ringbuffer_create(outbuf_size);
|
||||
|
||||
if (!in || !out) {
|
||||
fprintf(stderr, "memory allocation failure");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_set_buffer(compressor, in, out);
|
||||
b_compressor_set_mode(compressor, mode);
|
||||
fx_compressor_set_buffer(compressor, in, out);
|
||||
fx_compressor_set_mode(compressor, mode);
|
||||
|
||||
int ret = 0;
|
||||
while (1) {
|
||||
@@ -122,21 +122,21 @@ int main(int argc, const char **argv)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!b_ringbuffer_available_data_remaining(in)) {
|
||||
if (!fx_ringbuffer_available_data_remaining(in)) {
|
||||
break;
|
||||
}
|
||||
|
||||
status = b_compressor_step(compressor);
|
||||
status = fx_compressor_step(compressor);
|
||||
|
||||
if (status == B_ERR_NO_DATA) {
|
||||
if (status == FX_ERR_NO_DATA) {
|
||||
break;
|
||||
} else if (status == B_ERR_NO_SPACE) {
|
||||
} else if (status == FX_ERR_NO_SPACE) {
|
||||
ret = flush_output_buffer(out_fp, out);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "write error\n");
|
||||
break;
|
||||
}
|
||||
} else if (!B_OK(status)) {
|
||||
} else if (!FX_OK(status)) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -148,16 +148,16 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mode == B_COMPRESSOR_MODE_COMPRESS) {
|
||||
while (!b_compressor_eof(compressor)) {
|
||||
status = b_compressor_end(compressor);
|
||||
if (!B_OK(status)) {
|
||||
if (mode == FX_COMPRESSOR_MODE_COMPRESS) {
|
||||
while (!fx_compressor_eof(compressor)) {
|
||||
status = fx_compressor_end(compressor);
|
||||
if (!FX_OK(status)) {
|
||||
fprintf(stderr,
|
||||
"compression finalisation error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!b_ringbuffer_available_data_remaining(out)) {
|
||||
if (!fx_ringbuffer_available_data_remaining(out)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -171,13 +171,13 @@ int main(int argc, const char **argv)
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_compressor_unref(compressor);
|
||||
fx_compressor_unref(compressor);
|
||||
|
||||
fclose(in_fp);
|
||||
fclose(out_fp);
|
||||
|
||||
b_ringbuffer_unref(in);
|
||||
b_ringbuffer_unref(out);
|
||||
fx_ringbuffer_unref(in);
|
||||
fx_ringbuffer_unref(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <fx/compress/compressor.h>
|
||||
#include <fx/compress/cstream.h>
|
||||
#include <fx/compress/zstd.h>
|
||||
#include <fx/core/ringbuffer.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUF_SIZE 32
|
||||
|
||||
static int compress(b_type compressor_type, FILE *in, FILE *out)
|
||||
static int compress(fx_type compressor_type, FILE *in, FILE *out)
|
||||
{
|
||||
b_stream *out_stream = b_stream_open_fp(out);
|
||||
fx_stream *out_stream = fx_stream_open_fp(out);
|
||||
|
||||
b_cstream *cstream;
|
||||
b_status status = b_cstream_open(
|
||||
out_stream, compressor_type, B_COMPRESSOR_MODE_COMPRESS, &cstream);
|
||||
fx_cstream *cstream;
|
||||
fx_status status = fx_cstream_open(
|
||||
out_stream, compressor_type, FX_COMPRESSOR_MODE_COMPRESS, &cstream);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
fprintf(stderr, "cannot initialise compressor\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_cstream_begin_compressed_section(cstream, NULL);
|
||||
fx_cstream_begin_compressed_section(cstream, NULL);
|
||||
|
||||
char buf[4096];
|
||||
while (1) {
|
||||
size_t r = fread(buf, 1, sizeof buf, in);
|
||||
|
||||
size_t w = 0;
|
||||
b_cstream_write(cstream, buf, r, &w);
|
||||
fx_cstream_write(cstream, buf, r, &w);
|
||||
|
||||
if (r != w) {
|
||||
fprintf(stderr, "write error\n");
|
||||
@@ -41,35 +41,35 @@ static int compress(b_type compressor_type, FILE *in, FILE *out)
|
||||
}
|
||||
}
|
||||
|
||||
b_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(out_stream);
|
||||
fx_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
fx_cstream_unref(cstream);
|
||||
fx_stream_unref(out_stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int decompress(b_type compressor_type, FILE *in, FILE *out)
|
||||
static int decompress(fx_type compressor_type, FILE *in, FILE *out)
|
||||
{
|
||||
b_stream *in_stream = b_stream_open_fp(in);
|
||||
fx_stream *in_stream = fx_stream_open_fp(in);
|
||||
|
||||
b_cstream *cstream;
|
||||
b_status status = b_cstream_open(
|
||||
in_stream, compressor_type, B_COMPRESSOR_MODE_DECOMPRESS, &cstream);
|
||||
fx_cstream *cstream;
|
||||
fx_status status = fx_cstream_open(
|
||||
in_stream, compressor_type, FX_COMPRESSOR_MODE_DECOMPRESS, &cstream);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
fprintf(stderr, "cannot initialise compressor\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_cstream_begin_compressed_section(cstream, NULL);
|
||||
fx_cstream_begin_compressed_section(cstream, NULL);
|
||||
|
||||
char buf[4096];
|
||||
while (1) {
|
||||
size_t r = 0;
|
||||
b_status status = b_cstream_read(cstream, buf, sizeof buf, &r);
|
||||
if (!B_OK(status)) {
|
||||
fx_status status = fx_cstream_read(cstream, buf, sizeof buf, &r);
|
||||
if (!FX_OK(status)) {
|
||||
fprintf(stderr, "read error: %s\n",
|
||||
b_status_description(status));
|
||||
fx_status_description(status));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -84,9 +84,9 @@ static int decompress(b_type compressor_type, FILE *in, FILE *out)
|
||||
}
|
||||
}
|
||||
|
||||
b_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(in_stream);
|
||||
fx_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
fx_cstream_unref(cstream);
|
||||
fx_stream_unref(in_stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -98,11 +98,11 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_mode mode;
|
||||
fx_compressor_mode mode;
|
||||
if (!strcmp(argv[1], "C")) {
|
||||
mode = B_COMPRESSOR_MODE_COMPRESS;
|
||||
mode = FX_COMPRESSOR_MODE_COMPRESS;
|
||||
} else if (!strcmp(argv[1], "D")) {
|
||||
mode = B_COMPRESSOR_MODE_DECOMPRESS;
|
||||
mode = FX_COMPRESSOR_MODE_DECOMPRESS;
|
||||
} else {
|
||||
fprintf(stderr, "invalid mode %s\n", argv[1]);
|
||||
return -1;
|
||||
@@ -123,11 +123,11 @@ int main(int argc, const char **argv)
|
||||
|
||||
int ret = 0;
|
||||
switch (mode) {
|
||||
case B_COMPRESSOR_MODE_COMPRESS:
|
||||
ret = compress(B_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
|
||||
case FX_COMPRESSOR_MODE_COMPRESS:
|
||||
ret = compress(FX_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
|
||||
break;
|
||||
case B_COMPRESSOR_MODE_DECOMPRESS:
|
||||
ret = decompress(B_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
|
||||
case FX_COMPRESSOR_MODE_DECOMPRESS:
|
||||
ret = decompress(FX_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
|
||||
Reference in New Issue
Block a user