From 7b022006c47586dc00ed8bca85fcb0bdf5f9465d Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Sat, 3 Mar 2012 20:55:00 +0000
Subject: Add serd_chunk_sink for easy writing to a string.

git-svn-id: http://svn.drobilla.net/serd/trunk@329 490d8e77-9747-427b-9fa3-0b8f29cee8a0
---
 src/writer.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

(limited to 'src')

diff --git a/src/writer.c b/src/writer.c
index 8bdd3382..eb9c5b2d 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -714,3 +714,22 @@ serd_file_sink(const void* buf, size_t len, void* stream)
 {
 	return fwrite(buf, 1, len, (FILE*)stream);
 }
+
+SERD_API
+size_t
+serd_chunk_sink(const void* buf, size_t len, void* stream)
+{
+	SerdChunk* chunk = (SerdChunk*)stream;
+	chunk->buf = realloc((uint8_t*)chunk->buf, chunk->len + len);
+	memcpy((uint8_t*)chunk->buf + chunk->len, buf, len);
+	chunk->len += len;
+	return len;
+}
+
+SERD_API
+uint8_t*
+serd_chunk_sink_finish(SerdChunk* stream)
+{
+	serd_chunk_sink("", 1, stream);
+	return (uint8_t*)stream->buf;
+}
-- 
cgit v1.2.1