aboutsummaryrefslogtreecommitdiffstats
path: root/serd
diff options
context:
space:
mode:
Diffstat (limited to 'serd')
-rw-r--r--serd/serd.h98
1 files changed, 69 insertions, 29 deletions
diff --git a/serd/serd.h b/serd/serd.h
index fe2a08b2..612d2438 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -94,9 +94,6 @@ typedef struct SerdWriterImpl SerdWriter;
/// An interface that receives a stream of RDF data
typedef struct SerdSinkImpl SerdSink;
-/// A sink for bytes that receives string output
-typedef struct SerdByteSinkImpl SerdByteSink;
-
/// Return status code
typedef enum {
SERD_SUCCESS, ///< No error
@@ -112,7 +109,8 @@ typedef enum {
SERD_ERR_OVERFLOW, ///< Stack overflow
SERD_ERR_INVALID, ///< Invalid data
SERD_ERR_NO_DATA, ///< Unexpected end of input
- SERD_ERR_BAD_WRITE ///< Error writing to file/stream
+ SERD_ERR_BAD_WRITE, ///< Error writing to file/stream
+ SERD_ERR_BAD_CALL ///< Invalid call
} SerdStatus;
/// RDF syntax type
@@ -395,10 +393,13 @@ serd_base64_decode(void* buf, size_t* size, const char* str, size_t len);
/**
@}
- @name Byte Streams
+ @name Byte Source
@{
*/
+/// A source for bytes that provides text input
+typedef struct SerdByteSourceImpl SerdByteSource;
+
/**
Function to detect I/O stream errors
@@ -426,6 +427,67 @@ typedef size_t (*SerdReadFunc)(void* buf,
void* stream);
/**
+ Create a new byte source that reads from a string
+
+ @param string Null-terminated UTF-8 string to read from.
+ @param name Optional name of stream for error messages (string or URI).
+*/
+SERD_API
+SerdByteSource*
+serd_byte_source_new_string(const char* string, const SerdNode* name);
+
+/**
+ Create a new byte source that reads from a file
+
+ An arbitrary `FILE*` can be used via serd_byte_source_new_function() as
+ well, this is just a convenience function that opens the file properly,
+ sets flags for optimized I/O if possible, and automatically sets the name of
+ the source to the file path.
+
+ @param path Path of file to open and read from.
+ @param block_size Number of bytes to read per call.
+*/
+SERD_API
+SerdByteSource*
+serd_byte_source_new_filename(const char* path, size_t block_size);
+
+/**
+ Create a new byte source that reads from a user-specified function
+
+ The `stream` will be passed to the `read_func`, which is compatible with
+ the standard C `fread` if `stream` is a `FILE*`. Note that the serd Reader
+ only ever reads individual bytes at a time, that is, the `size` parameter
+ will always be 1 (but `nmemb` may be higher).
+
+ @param read_func Function called with bytes to consume.
+ @param error_func Stream error function with `ferror` semantics.
+ @param stream Context parameter passed to `read_func` and `error_func`.
+ @param name Optional name of stream for error messages (string or URI).
+ @param block_size Number of bytes to read per call.
+*/
+SERD_API
+SerdByteSource*
+serd_byte_source_new_function(SerdReadFunc read_func,
+ SerdStreamErrorFunc error_func,
+ void* stream,
+ const SerdNode* name,
+ size_t block_size);
+
+/// Free `source`
+SERD_API
+void
+serd_byte_source_free(SerdByteSource* source);
+
+/**
+ @}
+ @name Byte Sink
+ @{
+*/
+
+/// A sink for bytes that receives text output
+typedef struct SerdByteSinkImpl SerdByteSink;
+
+/**
Sink function for raw string output
Identical semantics to `fwrite`, but may set errno for more informative
@@ -1315,32 +1377,10 @@ SERD_API
void
serd_reader_add_blank_prefix(SerdReader* reader, const char* prefix);
-/// Prepare to read from the file at a local file `uri`
-SERD_API
-SerdStatus
-serd_reader_start_file(SerdReader* reader, const char* uri, bool bulk);
-
-/**
- Prepare to read from a stream
-
- The `read_func` is guaranteed to only be called for `page_size` elements
- with size 1 (i.e. `page_size` bytes).
-*/
-SERD_API
-SerdStatus
-serd_reader_start_stream(SerdReader* reader,
- SerdReadFunc read_func,
- SerdStreamErrorFunc error_func,
- void* stream,
- const SerdNode* name,
- size_t page_size);
-
-/// Prepare to read from a string
+/// Prepare to read from a byte source
SERD_API
SerdStatus
-serd_reader_start_string(SerdReader* reader,
- const char* utf8,
- const SerdNode* name);
+serd_reader_start(SerdReader* reader, SerdByteSource* byte_source);
/**
Read a single "chunk" of data during an incremental read