axl main logo
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules Pages
axlStream * axl_stream_new ( const char *  stream_source,
int  stream_size,
const char *  file_path,
int  fd_handler,
axlError **  error 
)

Creates a new byte stream using as data the string pointer and the size.

The axlStream object is an abstraction that allows to interface with a memory chunk, a file descriptor (or a socket) or a direct path, with a contenience API that allows inspecting and accepting the streamed content.

Here is an example on how to create an stream from a memory chunk:

1 axlStream * stream;
2 axlError * error;
3 
4 // create the stream and check result
5 stream = axl_stream_new (source_content, size_content, -1, NULL, &error);
6 if (stream == NULL) {
7  printf ("An error was found: %s\n", axl_error_get (error));
8  axl_error_free (error);
9  return;
10 }
11 
12 // stream created

In the case an stream is required to parse a file descriptor (including a socket):

1 stream = axl_stream_new (NULL, -1, NULL, fd, &error);

You can also provide a file path to let the axl stream module to open the file and buffer it as it requires to consume characters:

1 stream = axl_stream_new (NULL, -1, "c:/myFiles/document.xml", -1, &error);

Once initialized the axlStream object, you can use the following function to check and consume characters:

There alternatives APIs that allows to get the content until some patter is found (or a set of patterns):

Parameters
stream_sourceA pointer to the memory where the data to be streamed is located.
stream_sizeHow many bytes are available to perform streaming. You can pass a -1 value to allow the function to calculate the stream source size (stream_source param).
file_pathOptional parameter to allow reading the stream from a file using the open API.
fd_handlerOptional parameter to allow reading the stream from a file descriptor, that could be a file, a socket, etc..
errorOptional axlError reference where errors will be reported.
Returns
A newly allocated stream instance that should be deallocated by using axl_stream_free. The function could return a NULL value is received a NULL stream or a non positive stream size.

References axl_error_new(), AXL_LEVEL_CRITICAL, axl_log(), and axl_new.