add cluster i/o pipeline

This commit is contained in:
2025-01-30 18:10:38 +00:00
parent a69595b324
commit dad7c27bf6
18 changed files with 1147 additions and 50 deletions

View File

@@ -1,14 +1,16 @@
#include "bin.h"
#include "commands.h"
#include "write.h"
#include <blue/cmd.h>
#include <stdlib.h>
#include <blue/term.h>
#include <errno.h>
enum {
OPT_OUTPATH,
OPT_OUTPATH_PATH,
ARG_FILE,
ARG_FILE_PATH,
OPT_TAGGED_FILE,
OPT_TAGGED_FILE_TAG,
@@ -20,6 +22,65 @@ static int wrap(
const b_arglist *opt,
const b_array *args)
{
const char *in_path = NULL, *out_path = NULL;
b_arglist_get_string(opt, B_COMMAND_INVALID_ID, ARG_FILE, 0, &in_path);
b_arglist_get_string(opt, OPT_OUTPATH, OPT_OUTPATH_PATH, 0, &out_path);
printf("in path: %s\n", in_path);
printf("out path: %s\n", out_path);
FILE *inp = fopen(in_path, "rb");
if (!inp) {
b_err("cannot open '%s'", in_path);
b_i("reason: %s", strerror(errno));
return -1;
}
FILE *outp = fopen(out_path, "wb");
if (!outp) {
b_err("cannot open '%s'", out_path);
b_i("reason: %s", strerror(errno));
return -1;
}
struct ec3_writer *writer = NULL;
struct ec3_parameters param = {
.p_outp = outp,
.p_cluster_size = EC3_CLUSTER_16K,
.p_compression_func = EC3_COMPRESSION_ZSTD,
};
enum ec3_status status = ec3_writer_create(&param, &writer);
if (status != EC3_SUCCESS) {
b_err("cannot initialise EC3 writer");
return -1;
}
struct ec3_tag_writer *tag = NULL;
status = ec3_writer_create_tag(writer, EC3_TAG_BLOB, 0, 0, &tag);
if (status != EC3_SUCCESS) {
b_err("cannot initialise EC3 tag writer");
return -1;
}
char buf[4096];
while (1) {
size_t r = fread(buf, 1, sizeof buf, inp);
status = ec3_tag_writer_write(tag, buf, r);
if (r < sizeof buf) {
break;
}
}
ec3_tag_writer_finish(tag);
ec3_writer_finish(writer);
fclose(inp);
fclose(outp);
return 0;
}
@@ -29,8 +90,8 @@ B_COMMAND(CMD_WRAP, CMD_ROOT)
B_COMMAND_SHORT_NAME('W');
B_COMMAND_DESC(
"wrap one or more files into an ec3 container. each file will "
"be "
"stored in a separate blob tag within the created container.");
"be stored in a separate blob tag within the created "
"container.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(wrap);