ChaiLove API  0.28.0
Public Member Functions
love::data Class Reference

Provides functionality for creating and transforming data. More...

Public Member Functions

std::string compress (const std::string &str, int level)
 Compresses a string or data using a specific compression level. More...
 
std::string decompress (const std::string &str)
 Decompresses a compressed string. More...
 
std::string encode (const std::string &containerType, const std::string &format, const std::string &sourceString)
 Encode Data or a string to a Data or string in one of the EncodeFormats. More...
 
std::string decode (const std::string &containerType, const std::string &format, const std::string &sourceString)
 Decode Data or a string to a Data or string in one of the EncodeFormats. More...
 
std::string hash (const std::string &hashFunction, const std::string &data)
 Compute the message digest of specified string with specified algorithm. More...
 

Detailed Description

Provides functionality for creating and transforming data.

Member Function Documentation

◆ compress()

std::string love::data::compress ( const std::string &  str,
int  level 
)

Compresses a string or data using a specific compression level.

Parameters
strThe raw (un-compressed) string to compress.
level(-1) The level of compression to use, between 0 and 9. -1 indicates the default level.
Returns
Compressed data in the form of a string.
See also
love.data.decompress
var message = "Hello World!"
var compressed = love.data.compress(message)
print(compressed)
var decompressed = love.data.decompress(compressed)
print(decompressed)

◆ decode()

std::string love::data::decode ( const std::string &  containerType,
const std::string &  format,
const std::string &  sourceString 
)

Decode Data or a string to a Data or string in one of the EncodeFormats.

Parameters
containerTypeWhat type to return the decoded data as. Only supports "string" currently.
formatThe format of the input data. Can be "base64" or "hex".
sourceStringThe raw (encoded) data to decode.
Returns
String which contains the decoded version of source.
See also
love.data.encode

◆ decompress()

std::string love::data::decompress ( const std::string &  str)

Decompresses a compressed string.

Parameters
strA string containing data previously compressed with math.compress().
Returns
A string containing the raw decompressed data.
See also
love.data.compress

◆ encode()

std::string love::data::encode ( const std::string &  containerType,
const std::string &  format,
const std::string &  sourceString 
)

Encode Data or a string to a Data or string in one of the EncodeFormats.

Parameters
containerTypeWhat type to return the encoded data as. Only supports "string" currently.
formatThe format of the output data. Can be "base64" or "hex".
sourceStringThe raw data to encode.
Returns
String which contains the encoded version of source.
See also
love.data.decode

◆ hash()

std::string love::data::hash ( const std::string &  hashFunction,
const std::string &  data 
)

Compute the message digest of specified string with specified algorithm.

Parameters
hashFunctionHash algorithm to use (md5, sha1).
dataString to hash.
Returns
Raw message digest string.
var message = "Hello World!"
var hash = love.data.hash("md5", message)
print(hash)