Buffer#

Buffer objects are used for working with binary data. They can be used much like arrays, but are much more efficient since they only store bytes.

CONSTRUCTOR METHODS

Buffer()#

Constructor method.

Create a new empty buffer.

Returns:

Buffer.

EXAMPLE

var buffer = new mupdfjs.Buffer();
Buffer(data: string)#

New Buffer initialized with string contents as UTF-8.

Parameters:

datastring.

Returns:

Buffer.

Buffer(data: ArrayBuffer | Uint8Array)#

New Buffer initialized with typed array contents.

Parameters:

dataArrayBuffer | Uint8Array.

Returns:

Buffer.

EXAMPLE

let buffer = new mupdfjs.Buffer(fs.readFileSync("test.pdf"))

INSTANCE METHODS

getLength()#

Returns the number of bytes in the buffer.

Returns:

number.

EXAMPLE

var length = buffer.getLength();
writeByte(byte: number)#

Append a single byte to the end of the buffer.

Parameters:

bytenumber. The byte value. Only the least significant 8 bits of the value are appended to the buffer.

EXAMPLE

buffer.writeByte(0x2a);
readByte(at: number)#

Read the byte at the supplied index.

Parameters:

atnumber.

EXAMPLE

buffer.readByte(0);
write(str: string)#

Append string to the end of the buffer.

Parameters:

strstring.

EXAMPLE

buffer.write("hello world");
writeLine(str: string)#

Append string to the end of the buffer ending with a newline.

Parameters:

strstring.

EXAMPLE

buffer.writeLine("a line");
writeBuffer(data: Buffer | ArrayBuffer | Uint8Array | string)#

Append the contents of the data buffer to the end of the buffer.

Parameters:

dataBuffer | ArrayBuffer | Uint8Array | string. Data buffer.

EXAMPLE

buffer.writeBuffer(anotherBuffer);
slice(start: number, end: number)#

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.

Parameters:
  • startnumber. Start index.

  • endnumber. End index.

Returns:

Buffer.

EXAMPLE

var buffer = new mupdfjs.Buffer();
buffer.write("hello world"); // buffer contains "hello world"
var newBuffer = buffer.slice(1, -1); // newBuffer contains "ello worl"
asUint8Array()#

Returns the buffer as a Uint8Array.

Returns:

Uint8Array.

EXAMPLE

var arr = buffer.asUint8Array();
asString()#

Returns the buffer as a string.

Returns:

string.

EXAMPLE

var str = buffer.asString();

Code samples

Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:

import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"