istream.h revision daf029d2a627daa39d05507140f385162828172e
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch uoff_t v_offset, v_size, v_limit; /* relative to start_offset */
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschstruct istream *i_stream_create_file(int fd, pool_t pool,
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschstruct istream *i_stream_create_mmap(int fd, pool_t pool, size_t block_size,
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschstruct istream *i_stream_create_from_data(pool_t pool, const void *data,
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch/* Reference counting. References start from 1, so calling i_stream_unref()
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch destroys the stream if i_stream_ref() is never used. */
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch/* Return file descriptor for stream, or -1 if none is available. */
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch/* Mark the stream closed. Any reads after this will return -1. The data
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch already read can still be used. */
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch/* Change the maximum size for stream's input buffer to grow. Useful only
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch for buffered streams (currently only file). */
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Boschvoid i_stream_set_max_buffer_size(struct istream *stream, size_t max_size);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Change the start_offset and drop all data in buffers. Doesn't do anything
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if offset is the same as existing start_offset. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid i_stream_set_start_offset(struct istream *stream, uoff_t offset);
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch/* Stream won't be read past specified offset. Giving 0 as offset
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch removes the limit. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid i_stream_set_read_limit(struct istream *stream, uoff_t v_offset);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Makes reads blocking until at least one byte is read. timeout_cb is
45324f1eafa565dbc65e4dd335de9507dead55e6Timo Sirainen called if nothing is read in specified time. Setting timeout_msecs to 0
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch makes it non-blocking. This call changes non-blocking state of file
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch descriptor. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid i_stream_set_blocking(struct istream *stream, int timeout_msecs,
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch/* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch input buffer is full. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Skip forward a number of bytes. Never fails, the next read tells if it
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch was successful. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid i_stream_skip(struct istream *stream, uoff_t count);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Seek to specified position from beginning of file. Never fails, the next
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch read tells if it was successful. This works only for files. */
e9228a3918aa0243eff4aae1ff5462bd3198417fTimo Sirainenvoid i_stream_seek(struct istream *stream, uoff_t v_offset);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Reads the next line from stream and returns it, or NULL if more data is
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch needed to make a full line. NOTE: modifies the data in buffer for the \0,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch so it works only with buffered streams (currently only file). */
1e9296de32c9ddda40f33c06556cd568ddadf71fTimo Sirainenchar *i_stream_next_line(struct istream *stream);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Returns pointer to beginning of read data, or NULL if there's no data
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschconst unsigned char *i_stream_get_data(struct istream *stream, size_t *size);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Like i_stream_get_data(), but returns non-const data. This only works with
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch buffered streams (currently only file), others return NULL. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschunsigned char *i_stream_get_modifyable_data(struct istream *stream,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Like i_stream_get_data(), but read more when needed. Returns 1 if more
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch than threshold bytes are available, 0 if less, -1 if error or EOF with no
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch bytes available, or -2 if stream's input buffer is full. */
833bed942977673526c72e79bccc09314fc57104Phil Carmodyint i_stream_read_data(struct istream *stream, const unsigned char **data,