diff options
-rw-r--r-- | include/mupdf/fitz/stream.h | 5 | ||||
-rw-r--r-- | source/fitz/stream-read.c | 25 |
2 files changed, 30 insertions, 0 deletions
diff --git a/include/mupdf/fitz/stream.h b/include/mupdf/fitz/stream.h index f7eb6f16..fb3ef932 100644 --- a/include/mupdf/fitz/stream.h +++ b/include/mupdf/fitz/stream.h @@ -142,6 +142,11 @@ int fz_read(fz_stream *stm, unsigned char *data, int len); */ fz_buffer *fz_read_all(fz_stream *stm, int initial); +/* + fz_read_file: Read all the contents of a file into a buffer. +*/ +fz_buffer *fz_read_file(fz_context *ctx, const char *filename); + enum { FZ_STREAM_META_PROGRESSIVE = 1, diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index de314fe4..3144974e 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -161,3 +161,28 @@ int fz_stream_meta(fz_stream *stm, int key, int size, void *ptr) return -1; return stm->meta(stm, key, size, ptr); } + +fz_buffer * +fz_read_file(fz_context *ctx, const char *filename) +{ + fz_stream *stm; + fz_buffer *buf = NULL; + + fz_var(buf); + + stm = fz_open_file(ctx, filename); + fz_try(ctx) + { + buf = fz_read_all(stm, 0); + } + fz_always(ctx) + { + fz_close(stm); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } + + return buf; +} |