Moai SDK  2.0
MOAIDataBuffer Class Reference

Inherits MOAILuaObject.

Function List

base64Decode
 
base64Encode
 
clear
 
deflate
 
getSize
 
getString
 
hexDecode
 
hexEncode
 
inflate
 
load
 
loadAsync
 
save
 
saveAsync
 
setString
 
toCppHeader
 

Function Documentation

base64Decode

If a string is provided, decodes it as a base64 encoded string. Otherwise, decodes the current data stored in this object as a base64 encoded sequence of characters.


function base64Decode ( [ MOAIDataBuffer self, string data ] )

Parameters
MOAIDataBufferself Optional.
stringdata Optional. The string data to decode. You must either provide either a MOAIDataBuffer (via a :base64Decode type call) or string data (via a .base64Decode type call), but not both.
Returns
string output
base64Encode

If a string is provided, encodes it in base64. Otherwise, encodes the current data stored in this object as a base64 encoded sequence of characters.


function base64Encode ( [ MOAIDataBuffer self, string data ] )

Parameters
MOAIDataBufferself Optional.
stringdata Optional. The string data to encode. You must either provide either a MOAIDataBuffer (via a :base64Encode type call) or string data (via a .base64Encode type call), but not both.
Returns
string output
clear

Release the data buffer's memory.


function clear ( MOAIDataBuffer self )

Parameters
MOAIDataBufferself
Returns
nil
deflate

Compresses the string or the current data stored in this object using the DEFLATE algorithm.


function deflate ( string data [, number level, number windowBits ] )

Parameters
stringdata The string data to deflate.
numberlevel Optional. The level used in the DEFLATE algorithm.
numberwindowBits Optional. The window bits used in the DEFLATE algorithm.
Returns
string output
Note

function deflate ( MOAIDataBuffer self [, number level, number windowBits ] )

Parameters
MOAIDataBufferself
numberlevel Optional. The level used in the DEFLATE algorithm.
numberwindowBits Optional. The window bits used in the DEFLATE algorithm.
Returns
string output
Note
getSize

Returns the number of bytes in this data buffer object.


function getSize ( MOAIDataBuffer self )

Parameters
MOAIDataBufferself
Returns
number size
getString

Returns the contents of the data buffer object as a string value.


function getString ( MOAIDataBuffer self )

Parameters
MOAIDataBufferself
Returns
string data
hexDecode

If a string is provided, decodes it as a hex encoded string. Otherwise, decodes the current data stored in this object as a hex encoded sequence of bytes.


function hexDecode ( [ MOAIDataBuffer self, string data ] )

Parameters
MOAIDataBufferself Optional.
stringdata Optional. The string data to decode. You must either provide either a MOAIDataBuffer (via a :hexDecode type call) or string data (via a .hexDecode type call), but not both.
Returns
string output
hexEncode

If a string is provided, encodes it in hex. Otherwise, encodes the current data stored in this object as a hex encoded sequence of characters.


function hexEncode ( [ MOAIDataBuffer self, string data ] )

Parameters
MOAIDataBufferself Optional.
stringdata Optional. The string data to encode. You must either provide either a MOAIDataBuffer (via a :hexEncode type call) or string data (via a .hexEncode type call), but not both.
Returns
string output
inflate

Decompresses the string or the current data stored in this object using the DEFLATE algorithm.


function inflate ( string data [, number windowBits ] )

Parameters
stringdata The string data to inflate.
numberwindowBits Optional. The window bits used in the DEFLATE algorithm.
Returns
string output
Note

function inflate ( MOAIDataBuffer self [, number windowBits ] )

Parameters
MOAIDataBufferself
numberwindowBits Optional. The window bits used in the DEFLATE algorithm.
Returns
string output
Note
load

Copies the data from the given file into this object. This method is a synchronous operation and will block until the file is loaded.


function load ( MOAIDataBuffer self, string filename [, number detectZip, number windowBits ] )

Parameters
MOAIDataBufferself
stringfilename The path to the file that the data should be loaded from.
numberdetectZip Optional. One of MOAIDataBuffer.NO_INFLATE, MOAIDataBuffer.FORCE_INFLATE, MOAIDataBuffer.INFLATE_ON_EXT
numberwindowBits Optional. The window bits used in the DEFLATE algorithm. Pass nil to use the default value.
Returns
boolean success
loadAsync

Asynchronously copies the data from the given file into this object. This method is an asynchronous operation and will return immediately.


function loadAsync ( MOAIDataBuffer self, string filename, MOAITaskQueue queue [, function callback, number detectZip, boolean inflateAsync, number windowBits ] )

Parameters
MOAIDataBufferself
stringfilename The path to the file that the data should be loaded from.
MOAITaskQueuequeue The queue to perform the loading operation.
functioncallback Optional. The function to be called when the asynchronous operation is complete. The MOAIDataBuffer is passed as the first parameter.
numberdetectZip Optional. One of MOAIDataBuffer.NO_INFLATE, MOAIDataBuffer.FORCE_INFLATE, MOAIDataBuffer.INFLATE_ON_EXT
booleaninflateAsync Optional. 'true' to inflate on task thread. 'false' to inflate on subscriber thread. Default value is 'true.'
numberwindowBits Optional. The window bits used in the DEFLATE algorithm. Pass nil to use the default value.
Returns
nil
save

Saves the data in this object to the given file. This method is a synchronous operation and will block until the data is saved.


function save ( MOAIDataBuffer self, string filename )

Parameters
MOAIDataBufferself
stringfilename The path to the file that the data should be saved to.
Returns
boolean success
saveAsync

Asynchronously saves the data in this object to the given file. This method is an asynchronous operation and will return immediately.


function saveAsync ( MOAIDataBuffer self, string filename, MOAITaskQueue queue [, function callback ] )

Parameters
MOAIDataBufferself
stringfilename The path to the file that the data should be saved to.
MOAITaskQueuequeue The queue to perform the saving operation.
functioncallback Optional. The function to be called when the asynchronous operation is complete. The MOAIDataBuffer is passed as the first parameter.
Returns
nil
setString

Replaces the contents of this object with the string specified.


function setString ( MOAIDataBuffer self, string data )

Parameters
MOAIDataBufferself
stringdata The string data to replace the contents of this object with.
Returns
nil
toCppHeader

Convert data to CPP header file.


function toCppHeader ( string data, string name [, number columns ] )

Parameters
stringdata The string data to encode
stringname
numbercolumns Optional. Default value is 12
Returns
string output
Note

function toCppHeader ( MOAIDataBuffer data, string name [, number columns ] )

Parameters
MOAIDataBufferdata The data buffer to encode
stringname
numbercolumns Optional. Default value is 12
Returns
string output
Note