cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen#ifndef IOSTREAM_TEMP_H
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen#define IOSTREAM_TEMP_H
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainenenum iostream_temp_flags {
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainen /* if o_stream_send_istream() is called with a readable fd, don't
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainen actually copy the input stream, just have iostream_temp_finish()
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainen return a new iostream pointing to the fd dup()ed */
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainen IOSTREAM_TEMP_FLAG_TRY_FD_DUP = 0x01
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainen};
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainen
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen/* Start writing to given output stream. The data is initially written to
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen memory, and later to a temporary file that is immediately unlinked. */
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainenstruct ostream *iostream_temp_create(const char *temp_path_prefix,
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Sirainen enum iostream_temp_flags flags);
2f4f603d4cebab2cc956c72164efb02da83515c5Timo Sirainenstruct ostream *iostream_temp_create_named(const char *temp_path_prefix,
2f4f603d4cebab2cc956c72164efb02da83515c5Timo Sirainen enum iostream_temp_flags flags,
2f4f603d4cebab2cc956c72164efb02da83515c5Timo Sirainen const char *name);
8a8a3b43987b5ade914f22765e51c9e3de8179d3Timo Sirainenstruct ostream *iostream_temp_create_sized(const char *temp_path_prefix,
8a8a3b43987b5ade914f22765e51c9e3de8179d3Timo Sirainen enum iostream_temp_flags flags,
8a8a3b43987b5ade914f22765e51c9e3de8179d3Timo Sirainen const char *name,
8a8a3b43987b5ade914f22765e51c9e3de8179d3Timo Sirainen size_t max_mem_size);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen/* Finished writing to stream. Return input stream for it and free the
8a8a3b43987b5ade914f22765e51c9e3de8179d3Timo Sirainen output stream. (It's also possible to abort iostream-temp by simply
8a8a3b43987b5ade914f22765e51c9e3de8179d3Timo Sirainen destroying the ostream.) */
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenstruct istream *iostream_temp_finish(struct ostream **output,
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen size_t max_buffer_size);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen/* For internal testing: */
d97f081a3de44852197ced772e21560c108895a6Timo Sirainenint o_stream_temp_move_to_memory(struct ostream *output);
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen#endif