Data

This class lets you manipulate binary data.

Summary
This class lets you manipulate binary data.
The number of bytes the Data instance contains.
Returns the contents of the Data instance as a UTF8 string.
Determines if the contents of this Data instance are exactly equal to those of the other Data instance.
Copies the contents of another data instance into this one replacing any existing contents.
Loads this Data instance with the given string as UTF8.
Replaces the contents of this Data instance with the contents of the given file.
Writes the contents of this Data instance to the given file.
Loads the data object with the contents of the given url.
Interprets the contents of this data instance as a PLIST and converts it to an XML plist - which is returned as a string.
Interprets the contents of this data instance as a PLIST and converts it to a JavaScript object.
Treats the contents of the data instance as HTML and runs it through tidy to clean it and output XHTML

Properties

length

int length readonly

The number of bytes the Data instance contains.

Functions

asString

string asString(int encoding)

Returns the contents of the Data instance as a UTF8 string.

parameters

encodingAn optional integer that specifies the encoding to use.
If it is not given it will be assumed to be UTF8.  Other values are 1for ASCII,
5for ISO Latin 1, 7 - for non-lossy ASCII , 9 for ISO Latin 2.

returns

stringThe data as a string.

isEqualTo

bool isEqualTo(Data other)

Determines if the contents of this Data instance are exactly equal to those of the other Data instance.

parameters

otherA Data instance to compare to.

returns

trueIf they are equal.
falseOtherwise.

loadFromData

bool loadFromData(Data source)

Copies the contents of another data instance into this one replacing any existing contents.

parameters

sourceThe Data to copy from.

returns

trueThe copy succeeded.
falseOtherwise.

loadFromString

bool loadFromString(string source)

Loads this Data instance with the given string as UTF8.  Replaces any existing contents.

parameters

sourceThe string to copy from.

returns

trueIf everything was OK.
falseOtherwise.

loadFromFile

bool loadFromFile(string fileName)

Replaces the contents of this Data instance with the contents of the given file.

parameters

fileNameThe full path to the file to load.

returns

trueIf everything was OK.
falseOtherwise.

writeToFile

bool writeToFile(string fileName)

Writes the contents of this Data instance to the given file.  If the file exists, it will be replaced.  If it does not, it will be created.

parameters

fileNameThe full path to the file.

returns

trueIf it succeeded.
falseOtherwise.

loadFromURL

bool loadFromURL(string url)

Loads the data object with the contents of the given url.  This involves a synchronous fetch, so beware.

parameters

urlThe url to load from.

returns

trueIf it succeeded.
falseOtherwise.

asXMLPList

string asXMLPList()

Interprets the contents of this data instance as a PLIST and converts it to an XML plist - which is returned as a string.

asPList

jsval asPList()

Interprets the contents of this data instance as a PLIST and converts it to a JavaScript object.  The type depends on the plist.

asTidyXHTML

string asTidyXHTML()

Treats the contents of the data instance as HTML and runs it through tidy to clean it and output XHTML

int length readonly
The number of bytes the Data instance contains.
string asString(int encoding)
Returns the contents of the Data instance as a UTF8 string.
bool isEqualTo(Data other)
Determines if the contents of this Data instance are exactly equal to those of the other Data instance.
bool loadFromData(Data source)
Copies the contents of another data instance into this one replacing any existing contents.
bool loadFromString(string source)
Loads this Data instance with the given string as UTF8.
bool loadFromFile(string fileName)
Replaces the contents of this Data instance with the contents of the given file.
bool writeToFile(string fileName)
Writes the contents of this Data instance to the given file.
bool loadFromURL(string url)
Loads the data object with the contents of the given url.
string asXMLPList()
Interprets the contents of this data instance as a PLIST and converts it to an XML plist - which is returned as a string.
jsval asPList()
Interprets the contents of this data instance as a PLIST and converts it to a JavaScript object.
string asTidyXHTML()
Treats the contents of the data instance as HTML and runs it through tidy to clean it and output XHTML