#include <unistd.h>
-#define IOSTREAM_TEMP_MAX_BUF_SIZE (1024*128)
+#define IOSTREAM_TEMP_MAX_BUF_SIZE_DEFAULT (1024*128)
struct temp_ostream {
struct ostream_private ostream;
char *temp_path_prefix;
enum iostream_temp_flags flags;
+ size_t max_mem_size;
struct istream *dupstream;
uoff_t dupstream_offset, dupstream_start_offset;
return o_stream_temp_fd_sendv(tstream, iov, iov_count);
for (i = 0; i < iov_count; i++) {
- if (tstream->buf->used + iov[i].iov_len > IOSTREAM_TEMP_MAX_BUF_SIZE) {
+ if (tstream->buf->used + iov[i].iov_len > tstream->max_mem_size) {
if (o_stream_temp_move_to_fd(tstream) == 0) {
return o_stream_temp_fd_sendv(tstream, iov+i,
iov_count-i);
struct ostream *iostream_temp_create_named(const char *temp_path_prefix,
enum iostream_temp_flags flags,
const char *name)
+{
+ return iostream_temp_create_sized(temp_path_prefix, flags, name,
+ IOSTREAM_TEMP_MAX_BUF_SIZE_DEFAULT);
+}
+
+struct ostream *iostream_temp_create_sized(const char *temp_path_prefix,
+ enum iostream_temp_flags flags,
+ const char *name,
+ size_t max_mem_size)
{
struct temp_ostream *tstream;
struct ostream *output;
tstream->ostream.iostream.close = o_stream_temp_close;
tstream->temp_path_prefix = i_strdup(temp_path_prefix);
tstream->flags = flags;
+ tstream->max_mem_size = max_mem_size;
tstream->buf = buffer_create_dynamic(default_pool, 8192);
tstream->fd = -1;
struct ostream *iostream_temp_create_named(const char *temp_path_prefix,
enum iostream_temp_flags flags,
const char *name);
+struct ostream *iostream_temp_create_sized(const char *temp_path_prefix,
+ enum iostream_temp_flags flags,
+ const char *name,
+ size_t max_mem_size);
/* Finished writing to stream. Return input stream for it and free the
- output stream. */
+ output stream. (It's also possible to abort iostream-temp by simply
+ destroying the ostream.) */
struct istream *iostream_temp_finish(struct ostream **output,
size_t max_buffer_size);