diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-03-03 13:06:23 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-03-14 17:08:28 +0100 |
commit | a636786a2ea58082004f46ef34382e7f4c294e2d (patch) | |
tree | 497750831548d0da2d2724ac8f4007ed7490a7d1 /source/tools | |
parent | db8c7b6020199465ff395cff8ccd6c6f4be22d5a (diff) | |
download | mupdf-a636786a2ea58082004f46ef34382e7f4c294e2d.tar.xz |
js: Add buffer.save() to write contents of buffer to file.
Diffstat (limited to 'source/tools')
-rw-r--r-- | source/tools/murun.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c index 194bc6c2..79846fb9 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -1489,6 +1489,17 @@ static void ffi_Buffer_writeLine(js_State *J) rethrow(J); } +static void ffi_Buffer_save(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + fz_buffer *buf = js_touserdata(J, 0, "fz_buffer"); + const char *filename = js_tostring(J, 1); + fz_try(ctx) + fz_save_buffer(ctx, buf, filename); + fz_catch(ctx) + rethrow(J); +} + static void ffi_new_Document(js_State *J) { fz_context *ctx = js_getcontext(J); @@ -2670,6 +2681,7 @@ int murun_main(int argc, char **argv) jsB_propfun(J, "Buffer.writeRune", ffi_Buffer_writeRune, 1); jsB_propfun(J, "Buffer.writeLine", ffi_Buffer_writeLine, 1); jsB_propfun(J, "Buffer.write", ffi_Buffer_write, 1); + jsB_propfun(J, "Buffer.save", ffi_Buffer_save, 1); } js_setregistry(J, "fz_buffer"); |