BinaryData interface

A JavaScript object implementing the BinaryData interface represents binary data, for example, a file which has just been uploaded in an HTTP request.

BinaryData objects can be stored in the file store using O.file(), and returned as HTTP responses by assigning them to E.response.body.

Construction

Declare an as:"file" argument on a request handler.

Load a file from your plugin’s file directory with P.loadFile().

Construct binary data with O.binaryData().

Create an output file with a generator.

Interface

property digest

The digest of the file, as a hex encoded String.

property fileSize

The size of the file, in bytes, as a number.

property mimeType

The MIME type of the file. Note that some MIME types are standardised as browsers tend to be a bit inconsistent.

property filename

The filename of the file, as set by the browser.

function readAsString(charsetName)

Return the contents of the binary data, interpreted as a string in the given character set, eg "UTF-8".

Use this function with care, checking the fileSize property before calling it, as it is very easy to accidentally run out of memory.

function readAsJSON()

Parse the contents of the binary data as JSON, returning the JavaScript data structure. The data must be a valid UTF-8 string.