13.2 Creation

The exact function to call to create an output stream depends on the specific stream required, but they generally follow a similar format. Some common examples are:

/* 
   fz_new_output_with_file: Open an output stream that writes to a 
   FILE *. 
 
   file: The file to write to. 
 
   close: non-zero if we should close the file when the fz_output 
   is closed. 
*/ 
fz_output *fz_new_output_with_file_ptr(fz_context *ctx, FILE *file, int close); 
 
/* 
   fz_new_output_with_path: Open an output stream that writes to a 
   given path. 
 
   filename: The filename to write to (specified in UTF-8). 
 
   append: non-zero if we should append to the file, rather than 
   overwriting it. 
*/ 
fz_output *fz_new_output_with_path(fz_context *, const char *filename, int append); 
 
/* 
   fz_new_output_with_buffer: Open an output stream that appends 
   to a buffer. 
 
   buf: The buffer to append to. 
*/ 
fz_output *fz_new_output_with_buffer(fz_context *ctx, fz_buffer *buf);

One of the most common use cases is to get an output stream that goes to stdout or stderr, and we provide convenience functions for exactly this. In addition we allow the streams for stdout and stderr to be replaced by other fz_outputs, thus allowing redirection to be changed simply for any of our existing tools:

/* 
   fz_stdout: The standard out output stream. By default 
   this stream writes to stdout. This may be overridden 
   using fz_set_stdout. 
*/ 
fz_output *fz_stdout(fz_context *ctx); 
 
/* 
   fz_stderr: The standard error output stream. By default 
   this stream writes to stderr. This may be overridden 
   using fz_set_stderr. 
*/ 
fz_output *fz_stderr(fz_context *ctx); 
 
/* 
   fz_set_stdout: Replace default standard output stream 
   with a given stream. 
 
   out: The new stream to use. 
*/ 
void fz_set_stdout(fz_context *ctx, fz_output *out); 
 
/* 
   fz_set_stderr: Replace default standard error stream 
   with a given stream. 
 
   err: The new stream to use. 
*/ 
void fz_set_stderr(fz_context *ctx, fz_output *err);