Buffer objects are used for working with binary data, e.g. returned
from asJPEG. They can be used much like arrays, but are
much more efficient since they only store bytes.
Creates a new Buffer initialized with contents from data.
Buffer | ArrayBuffer | Uint8Array | string | null) –
Contents used to populate buffer, or leave it empty if
null.var buffer = new mupdf.Buffer("hello world")The number of bytes in this buffer (read-only).
only mutool run
Get or set the byte at index n.
See readByte()
and writeByte()
for the equivalent in mupdf.js.
var byte = buffer[0]Returns the contents of this buffer as a string.
var str = buffer.asString()only mupdf.js
Returns the contents of this buffer as a Uint8Array.
var arr = buffer.asUint8Array()Returns the number of bytes in this buffer.
var length = buffer.getLength()Returns the byte at the specified index at if within
0 <= at < getLength(). Otherwise returns
undefined.
number) – Index to read byte
at.buffer.readByte(0)Create a new buffer containing a (subset of) the data in this buffer.
Start and end are offsets from the beginning of this buffer, and if
negative from the end of this buffer. If start points to
the end of this buffer, or if end point to at or before
start, then an empty buffer will be returned.
number) – Start index.number) – End index
(optional).var buffer = new mupdf.Buffer()
buffer.write("hello world") // buffer contains "hello world"
var newBuffer = buffer.slice(1, -1) // newBuffer contains "ello worl"Append the string as UTF-8 to the end of this buffer.
string) – String to append.buffer.write("hello world")Append the contents of the data buffer to the end of
this buffer.
Buffer | ArrayBuffer | Uint8Array | string) – Data buffer
to append.buffer.writeBuffer(anotherBuffer)Append a single byte to the end of this buffer. Only the least significant 8 bits of the value are appended.
number) – The byte value to
append.buffer.writeByte(0x2a)Append string to the end of this buffer ending with a newline.
string) – String to append.buffer.writeLine("a line")only mutool run
Encode a unicode character as UTF-8 and append to the end of the buffer.
number) – The character unicode
codepoint.buffer.writeRune(0x4f60) // To append U+4f60, 你
buffer.writeRune(0x597d) // To append U+597d, 好
buffer.writeRune(0xff01) // To append U+ff01, !Write the contents of the buffer to a file.
string) – Filename to save
to.buffer.save("buffer.dat")