aboutsummaryrefslogtreecommitdiffstats
path: root/src/serdi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/serdi.c')
-rw-r--r--src/serdi.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 5cea387e..2819788d 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -115,6 +115,22 @@ quiet_error_sink(void* handle, const SerdError* e)
return SERD_SUCCESS;
}
+/** fread-like wrapper for getc (which is faster). */
+static size_t
+serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream)
+{
+ (void)size;
+ (void)nmemb;
+
+ const int c = getc((FILE*)stream);
+ if (c == EOF) {
+ *((uint8_t*)buf) = 0;
+ return 0;
+ }
+ *((uint8_t*)buf) = (uint8_t)c;
+ return 1;
+}
+
int
main(int argc, char** argv)
{
@@ -284,17 +300,21 @@ main(int argc, char** argv)
SerdStatus status = SERD_SUCCESS;
if (!from_file) {
- status = serd_reader_read_string(reader, input);
- } else if (bulk_read) {
- status = serd_reader_read_file_handle(reader, in_fd, in_name);
+ status = serd_reader_start_string(reader, input);
} else {
- status = serd_reader_start_stream(reader, in_fd, in_name, false);
- while (!status) {
- status = serd_reader_read_chunk(reader);
- }
- serd_reader_end_stream(reader);
+ status = serd_reader_start_stream(
+ reader,
+ bulk_read ? (SerdSource)fread : serd_file_read_byte,
+ (SerdStreamErrorFunc)ferror,
+ in_fd,
+ in_name,
+ bulk_read ? SERD_PAGE_SIZE : 1);
}
+ status = serd_reader_read_document(reader);
+
+ serd_reader_end_stream(reader);
+
serd_reader_free(reader);
serd_writer_finish(writer);
serd_writer_free(writer);