aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/serd/serd.h7
-rw-r--r--src/serdi.c17
-rw-r--r--src/writer.c13
-rw-r--r--test/test_reader_writer.c10
4 files changed, 28 insertions, 19 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 66f22cbd..6abadf04 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -1604,9 +1604,8 @@ typedef struct SerdWriterImpl SerdWriter;
*/
typedef enum {
SERD_WRITE_ASCII = 1u << 0u, ///< Escape all non-ASCII characters
- SERD_WRITE_BULK = 1u << 1u, ///< Write output in pages
- SERD_WRITE_UNQUALIFIED = 1u << 2u, ///< Do not shorten URIs into CURIEs
- SERD_WRITE_UNRESOLVED = 1u << 3u ///< Do not make URIs relative
+ SERD_WRITE_UNQUALIFIED = 1u << 1u, ///< Do not shorten URIs into CURIEs
+ SERD_WRITE_UNRESOLVED = 1u << 2u ///< Do not make URIs relative
} SerdWriterFlag;
/// Bitwise OR of SerdWriterFlag values
@@ -1619,7 +1618,7 @@ serd_writer_new(SerdWorld* SERD_NONNULL world,
SerdSyntax syntax,
SerdWriterFlags flags,
SerdEnv* SERD_NONNULL env,
- SerdWriteFunc SERD_NONNULL ssink,
+ SerdWriteFunc SERD_NONNULL write_func,
void* SERD_NULLABLE stream);
/// Free `writer`
diff --git a/src/serdi.c b/src/serdi.c
index 3f4593db..4b201237 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -219,8 +219,7 @@ main(int argc, char** argv)
}
const SerdWriterFlags writer_flags =
- ((ascii ? SERD_WRITE_ASCII : 0u) | //
- (bulk_write ? SERD_WRITE_BULK : 0u) | //
+ ((ascii ? SERD_WRITE_ASCII : 0u) | //
(full_uris ? (SERD_WRITE_UNQUALIFIED | SERD_WRITE_UNRESOLVED) : 0u));
SerdNode* base = NULL;
@@ -235,8 +234,16 @@ main(int argc, char** argv)
SerdEnv* const env =
serd_env_new(base ? serd_node_string_view(base) : SERD_EMPTY_STRING());
- SerdWriter* const writer = serd_writer_new(
- world, output_syntax, writer_flags, env, (SerdWriteFunc)fwrite, out_fd);
+ SerdByteSink* const byte_sink =
+ serd_byte_sink_new((SerdWriteFunc)fwrite, out_fd, bulk_write ? 4096u : 1u);
+
+ SerdWriter* const writer =
+ serd_writer_new(world,
+ output_syntax,
+ writer_flags,
+ env,
+ (SerdWriteFunc)serd_byte_sink_write,
+ byte_sink);
SerdReader* const reader =
serd_reader_new(world, input_syntax, serd_writer_sink(writer), stack_size);
@@ -278,9 +285,9 @@ main(int argc, char** argv)
serd_reader_finish(reader);
serd_reader_free(reader);
- serd_writer_finish(writer);
serd_writer_free(writer);
serd_node_free(input_name);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
serd_node_free(base);
serd_world_free(world);
diff --git a/src/writer.c b/src/writer.c
index a6f73a89..bd6caf1e 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -92,7 +92,8 @@ struct SerdWriterImpl {
SerdNode* root_node;
SerdURIView root_uri;
SerdStack anon_stack;
- SerdByteSink* byte_sink;
+ SerdWriteFunc write_func;
+ void* stream;
WriteContext context;
SerdNode* list_subj;
unsigned list_depth;
@@ -155,7 +156,7 @@ ctx(SerdWriter* writer, const SerdField field)
static size_t
sink(const void* buf, size_t len, SerdWriter* writer)
{
- return serd_byte_sink_write(buf, 1, len, writer->byte_sink);
+ return writer->write_func(buf, 1, len, writer->stream);
}
// Write a single character, as an escape for single byte characters
@@ -943,7 +944,6 @@ serd_writer_finish(SerdWriter* writer)
if (ctx(writer, SERD_GRAPH)) {
write_sep(writer, SEP_GRAPH_END);
}
- serd_byte_sink_flush(writer->byte_sink);
free_context(&writer->context);
writer->indent = 0;
writer->context = WRITE_CONTEXT_NULL;
@@ -955,7 +955,7 @@ serd_writer_new(SerdWorld* world,
SerdSyntax syntax,
SerdWriterFlags flags,
SerdEnv* env,
- SerdWriteFunc ssink,
+ SerdWriteFunc write_func,
void* stream)
{
const WriteContext context = WRITE_CONTEXT_NULL;
@@ -968,11 +968,11 @@ serd_writer_new(SerdWorld* world,
writer->root_node = NULL;
writer->root_uri = SERD_URI_NULL;
writer->anon_stack = serd_stack_new(SERD_PAGE_SIZE);
+ writer->write_func = write_func;
+ writer->stream = stream;
writer->context = context;
writer->list_subj = NULL;
writer->empty = true;
- writer->byte_sink = serd_byte_sink_new(
- ssink, stream, (flags & SERD_WRITE_BULK) ? SERD_PAGE_SIZE : 1);
writer->iface.handle = writer;
writer->iface.on_event = (SerdEventFunc)serd_writer_on_event;
@@ -1083,7 +1083,6 @@ serd_writer_free(SerdWriter* writer)
serd_stack_free(&writer->anon_stack);
free(writer->bprefix);
- serd_byte_sink_free(writer->byte_sink);
serd_node_free(writer->root_node);
free(writer);
}
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index 706f5962..ec9f194b 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -242,9 +242,12 @@ test_writer(const char* const path)
serd_writer_free(writer);
// Test buffer sink
- SerdBuffer buffer = {NULL, 0};
- writer =
- serd_writer_new(world, SERD_TURTLE, 0, env, serd_buffer_sink, &buffer);
+ SerdBuffer buffer = {NULL, 0};
+ SerdByteSink* byte_sink =
+ serd_byte_sink_new((SerdWriteFunc)serd_buffer_sink, &buffer, 1);
+
+ writer = serd_writer_new(
+ world, SERD_TURTLE, 0, env, (SerdWriteFunc)serd_byte_sink_write, byte_sink);
const SerdNode* const base =
serd_nodes_uri(nodes, SERD_STRING("http://example.org/base"));
@@ -252,6 +255,7 @@ test_writer(const char* const path)
serd_writer_set_base_uri(writer, base);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
char* out = serd_buffer_sink_finish(&buffer);
assert(!strcmp(out, "@base <http://example.org/base> .\n"));