diff options
Diffstat (limited to 'src/reader.c')
-rw-r--r-- | src/reader.c | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/src/reader.c b/src/reader.c index 9a3da25f..28c2b2f0 100644 --- a/src/reader.c +++ b/src/reader.c @@ -219,37 +219,6 @@ serd_reader_set_default_graph(SerdReader* reader, reader->default_graph = serd_node_copy(graph); } -SerdStatus -serd_reader_read_file(SerdReader* reader, - const char* uri) -{ - char* const path = serd_file_uri_parse(uri, NULL); - if (!path) { - return SERD_ERR_BAD_ARG; - } - - FILE* fd = serd_fopen(path, "rb"); - if (!fd) { - free(path); - return SERD_ERR_UNKNOWN; - } - - SerdStatus st = serd_reader_start_stream( - reader, (SerdSource)fread, (SerdStreamErrorFunc)ferror, - fd, path, SERD_PAGE_SIZE); - - if (!st) { - st = serd_reader_read_document(reader); - } - - const SerdStatus est = serd_reader_end_stream(reader); - - fclose(fd); - free(path); - - return st ? st : est; -} - static SerdStatus skip_bom(SerdReader* me) { @@ -276,7 +245,31 @@ serd_reader_start_stream(SerdReader* reader, size_t page_size) { return serd_byte_source_open_source( - &reader->source, read_func, error_func, stream, name, page_size); + &reader->source, read_func, error_func, NULL, stream, name, page_size); +} + +SerdStatus +serd_reader_start_file(SerdReader* reader, const char* uri, bool bulk) +{ + char* const path = serd_file_uri_parse(uri, NULL); + if (!path) { + return SERD_ERR_BAD_ARG; + } + + FILE* fd = serd_world_fopen(reader->world, path, "rb"); + free(path); + if (!fd) { + return SERD_ERR_UNKNOWN; + } + + return serd_byte_source_open_source( + &reader->source, + bulk ? (SerdSource)fread : serd_file_read_byte, + (SerdStreamErrorFunc)ferror, + (SerdStreamCloseFunc)fclose, + fd, + uri, + bulk ? SERD_PAGE_SIZE : 1); } SerdStatus |