12.2 Creation

The exact mechanism for creating a stream depends upon the source for that particular stream, but typically it will involve a call to a creation function, such as fz_open_file.

/* 
   fz_open_file: Open the named file and wrap it in a stream. 
 
   filename: Path to a file. On non-Windows machines the filename should 
   be exactly as it would be passed to fopen(2). On Windows machines, 
   the path should be UTF-8 encoded so that non-ASCII characters can be 
   represented. Other platforms do the encoding as standard anyway (and 
   in most cases, particularly for MacOS and Linux, the encoding they 
   use is UTF-8 anyway). 
*/ 
fz_stream *fz_open_file(fz_context *ctx, const char *filename);

Alternative functions exist to allow creating streams from C level FILE pointers:

/* 
   fz_open_file: Wrap an open file descriptor in a stream. 
 
   file: An open file descriptor supporting bidirectional 
   seeking. The stream will take ownership of the file 
   descriptor, so it may not be modified or closed after the call 
   to fz_open_file_ptr. When the stream is closed it will also close 
   the file descriptor. 
*/ 
fz_stream *fz_open_file_ptr(fz_context *ctx, FILE *file);

from direct memory blocks:

/* 
   fz_open_memory: Open a block of memory as a stream. 
 
   data: Pointer to start of data block. Ownership of the data block is 
   NOT passed in. 
 
   len: Number of bytes in data block. 
 
   Returns pointer to newly created stream. May throw exceptions on 
   failure to allocate. 
*/ 
fz_stream *fz_open_memory(fz_context *ctx, unsigned char *data, size_t len);

and from fz_buffers:

/* 
   fz_open_buffer: Open a buffer as a stream. 
 
   buf: The buffer to open. Ownership of the buffer is NOT passed in 
   (this function takes its own reference). 
 
   Returns pointer to newly created stream. May throw exceptions on 
   failure to allocate. 
*/ 
fz_stream *fz_open_buffer(fz_context *ctx, fz_buffer *buf);

There are too many other options for creating streams to list them all here, but their use should be self evident from the header file definitions. Once created, all streams can be used in the same ways.