Skip to content

Latest commit

 

History

History

asset

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

asset module


Access

gracenode.asset

Configurations

"modules": {
	"asset": {
		"path": "pathToAssetDirectory"
	}
}

#####API: getOne

Object getOne(String pathName)

Returns asset file object(s).

// to get a file object of /img/backgrounds/bg001.png
var bg001 = gracenode.asset.getOne('img/backgrounds/bg001');
/*
* bg001 will be:
* { key: 'img/backgrounds/bg001', type: 'png', hash: 'fd8g0f8gd==' }
*/
// to get all file objects in /img/backgrounds/
var backgrounds = gracenode.asset.getOne('img/backgrounds/');
/*
* backgrounds will be:
* { bg001: {file object}, bg002: {file object}, bg003: {file object} }
*/

#####API: getMany

Array getMany(Array pathNameList)

Returns an array of asset file object(s)

#####API: getDataByKey

Object getDataByKey(String assetFileKey)

Returns an asset data object

// to get the binary data of /img/backgrounds/bg001.png
var bg001 = gracenode.asset.getOne('img/backgrounds/bg001');
var bg001Data = gracenode.asset.getDataByKey(bg001.key);
/*
* bg001Data will be:
* { data: binary data of the file, path: '~asset/img/backgrounds/bg001.png' }
*/

#####API: getDataByKeyAndHash

Object getDataByKeyAndHash(String assetFileKey, String assetFileHash, Function callback)

Returns an asset data object.

If the file hash is old, the function will read the file and update the cache map before returning the data object

var bg001 = gracenode.asset.getOne('img/backgrounds/bg001');
gracenode.asset.getDataByKeyAndHash(bg001.key, bg001.hash, function (error, bg001Data) {
	if (error) {
		// handle error
	}
	// do something here
});