test: update b_stream usage
This commit is contained in:
21
test/cat.c
21
test/cat.c
@@ -1,7 +1,8 @@
|
||||
#include <blue/core/stream.h>
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
@@ -13,25 +14,19 @@ int main(int argc, const char **argv)
|
||||
const char *path_cstr = argv[1];
|
||||
b_path *path = b_path_create_from_cstr(path_cstr);
|
||||
|
||||
b_file *file = NULL;
|
||||
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &file);
|
||||
b_file *src = NULL;
|
||||
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
b_stream *src_stream, *dest_stream;
|
||||
|
||||
b_file_open_stream(file, &src_stream);
|
||||
|
||||
b_string *str = b_string_create();
|
||||
b_stream_pipeline *pipeline;
|
||||
b_status status = b_string_open_stream(str, &dest_stream);
|
||||
|
||||
b_stream_pipeline_create(1024, &pipeline);
|
||||
b_stream_buffer *buf = b_stream_buffer_create_dynamic(1024);
|
||||
|
||||
size_t nr_read;
|
||||
b_stream_read_all_bytes_s(src_stream, dest_stream, pipeline, &nr_read);
|
||||
b_stream_read_all_bytes_s(src, b_stdout, buf, &nr_read);
|
||||
|
||||
b_stream_buffer_unref(buf);
|
||||
|
||||
printf("%s\n", b_string_ptr(str));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,23 +12,19 @@ int main(int argc, const char **argv)
|
||||
const char *path_cstr = argv[1];
|
||||
b_path *path = b_path_create_from_cstr(path_cstr);
|
||||
|
||||
b_file *file = NULL;
|
||||
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &file);
|
||||
b_file *src = NULL;
|
||||
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_stream *src_stream;
|
||||
|
||||
b_file_open_stream(file, &src_stream);
|
||||
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
|
||||
b_object *data;
|
||||
b_status status = b_serial_ctx_deserialise(
|
||||
ctx, B_SERIAL_FORMAT_JSON, src_stream, &data, 0);
|
||||
ctx, B_SERIAL_FORMAT_JSON, src, &data, 0);
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot read data\n");
|
||||
return -1;
|
||||
@@ -38,6 +34,7 @@ int main(int argc, const char **argv)
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_object_unref(data);
|
||||
b_object_unref(src);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1 +1 @@
|
||||
tab = 32
|
||||
k = "v"
|
||||
|
||||
@@ -12,23 +12,19 @@ int main(int argc, const char **argv)
|
||||
const char *path_cstr = argv[1];
|
||||
b_path *path = b_path_create_from_cstr(path_cstr);
|
||||
|
||||
b_file *file = NULL;
|
||||
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &file);
|
||||
b_file *src = NULL;
|
||||
b_result result = b_file_open(NULL, path, B_FILE_READ_ONLY, &src);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_stream *src_stream;
|
||||
|
||||
b_file_open_stream(file, &src_stream);
|
||||
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
|
||||
b_object *data = NULL;
|
||||
b_status status = b_serial_ctx_deserialise(
|
||||
ctx, B_SERIAL_FORMAT_TOML, src_stream, &data, 0);
|
||||
ctx, B_SERIAL_FORMAT_TOML, src, &data, 0);
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot read data\n");
|
||||
return -1;
|
||||
@@ -42,6 +38,7 @@ int main(int argc, const char **argv)
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_object_unref(data);
|
||||
b_object_unref(src);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user