AxLoader

Summary
AxLoader
Functions
startLoadingBegin loading a folder.
fromBuffersGets the archive from the cached buffer and the patch/base buffer.
getVersionTakes an archive and returns the version number.
isUpdateNeededReads the cached version and determines if it is up to date.
setCachedSets the cached data for a folder.
getCachedGets the cached data for a folder.
clearCachedRemoves items from the cache.
postProcessRuns all the functions in the tasks array against all the properties on files.
fileLoadCallbackThe callback for when a file is extracted out of the archive.
getAvalibleFileListGets a list of the avalible files for download.
getMostAppropriateFileGets the file that should be downloaded.
Variables
POST_TASKSA collection of postprocessing functions for passing to startLoading’s postTasks parameter.
Functions
EVAL_AS_JSEvaluates a script files in a special way that plays nicely with the debugger.
STRINGIFYDecode files into strings if they match the passed extionstion.
PARSE_AS_JSONDecode files into strings if they match the passed extionstion.
USE_AS_CSSDecode files into strings if they match the passed extionstion.
BASE64IFYDecode files into base64strings if they match the passed extionstion.
BASE64IFY_FILES_WITH_EXTDecode files into base64strings if they match the passed extionstion.
REMOVE_FILE_EXTSRemoves file extentions.
EXPAND_FOLDERSExpands the folder structure of the files in the archive.
Variables
FILTERContains post processing tasks that filter out files for other post tasks.
Functions
WITH_EXTA filter that calls the passed function if the name matches the passed file extention.
WITH_FILEA filter than calls the passed function if the names match.
WITH_FILEA filter than calls the passed function if the names match.
WITHOUTA filter than calls the passed function if the names don’t match.
decodeStringReturns a string from a UTF8 encoded arraybuffer.
decodeBase64https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
encodeBase64https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
checkForUpdatesPasses true to the callback if there are updates.

Functions

startLoading

function startLoading(folder,
events,
postTasks)

Begin loading a folder.

Parameters

folder(String) Which folder to load.
events(Object) An object containing all the callbacks.  (onError, onProgress, onComplete).
postTasks(Array) A list of things to do to process the data after loading it.

fromBuffers

function fromBuffers(cached,
uptodate,
folder,
events,
postTasks)

Gets the archive from the cached buffer and the patch/base buffer.  Calls the onComplete event when done.

Parameters

cachedThe cached version of the file.
uptodateThe up to date base version or patch to an up to date version from the cached version.
folderThe name of the origin folder.
eventsThe events object passed to startLoading.
postTasksA list of functions to call on each of the files.

getVersion

function getVersion(ar)

Takes an archive and returns the version number.

Parameters

arAn archive.

Returns

(number) Version number.

isUpdateNeeded

function isUpdateNeeded(filename,
cachedArchive)

Reads the cached version and determines if it is up to date.

Parameters

versionthe current up to date version.

Returns

(boolean) True if up to date.

setCached

function setCached(folder,
buffer)

Sets the cached data for a folder.

Parameters

folderThe name of the origin of the buffer.
bufferThe buffer to cache.

getCached

function getCached(folder)

Gets the cached data for a folder.

Parameters

folderThe name of the origin of the buffer.

Retruns

The cached buffer.

clearCached

var clearCached = function (rest)

Removes items from the cache.

Parameters

rest...The cached folders to remove.

postProcess

function postProcess(files,
tasks)

Runs all the functions in the tasks array against all the properties on files.

Parameters

files(Object) An object containing all the file data.
tasks(Array) An array of functions to call for each file.

fileLoadCallback

The callback for when a file is extracted out of the archive.

Properties

name(String) The name of the file.
folder(String) The name of the asset folder wr’re loading
data(Uint8Array) The binary data of the file.
output(Object) The data gets put here.

getAvalibleFileList

function getAvalibleFileList(callback)

Gets a list of the avalible files for download.

Parameters

callback(Function) Callback on done.  Takes an array of strings.

getMostAppropriateFile

function getMostAppropriateFile(folder,
cachedVersion,
callback)

Gets the file that should be downloaded.  Always picks the file with the highest version number, non-numeric values have a version value of -1.  If a patch exists from the cached version to the highest version, that will be picked over the base version.

Parameters

folder(String) The data being requested
callback(Function) On done.  Takes one parameter, the picked file name.

Variables

POST_TASKS

A collection of postprocessing functions for passing to startLoading’s postTasks parameter.

All of them take the same set of parameters.  Parameters: name - the name of the file. data - the data in the file. output - the object onto which the files should be attached.

Functions

EVAL_AS_JS

EVAL_AS_JS: function (name,
data,
output)

Evaluates a script files in a special way that plays nicely with the debugger.

STRINGIFY

STRINGIFY: function (name,
data,
output)

Decode files into strings if they match the passed extionstion.

Parameters

extThe extention to match.  Don’t include the dot.

PARSE_AS_JSON

PARSE_AS_JSON: function (name,
data,
output)

Decode files into strings if they match the passed extionstion.

Parameters

extThe extention to match.  Don’t inclide the dot.

USE_AS_CSS

USE_AS_CSS: function (name,
data,
output)

Decode files into strings if they match the passed extionstion.

Parameters

extThe extention to match.  Don’t inclide the dot.

BASE64IFY

BASE64IFY: function (name,
data,
output)

Decode files into base64strings if they match the passed extionstion.

Parameters

mimethe mime type of the file.  If included, files will be transformed into a data url, otherwise it will be plain data.

BASE64IFY_FILES_WITH_EXT

Decode files into base64strings if they match the passed extionstion.

Parameters

mimethe mime type of the file.

REMOVE_FILE_EXTS

REMOVE_FILE_EXTS: function (name,
data,
output)

Removes file extentions.

EXPAND_FOLDERS

EXPAND_FOLDERS: function (name,
data,
output)

Expands the folder structure of the files in the archive.  So for example, if you have a file called “folder/file”, you’ll be able to access it using assets.folder.file instead of assets[“folder/file”].

Variables

FILTER

var FILTER

Contains post processing tasks that filter out files for other post tasks.

Functions

WITH_EXT

WITH_EXT: function (ext,
f)

A filter that calls the passed function if the name matches the passed file extention.

WITH_FILE

WITH_FILE: function (n,
f)

A filter than calls the passed function if the names match.

WITH_FILE

A filter than calls the passed function if the names match.

WITHOUT

WITHOUT: function (re,
f)

A filter than calls the passed function if the names don’t match.

decodeString

function decodeString (buffer)

Returns a string from a UTF8 encoded arraybuffer.  Comes from: https://gist.github.com/boushley/5471599

Parameters

buffer(ArrayBuffer) The buffer with the encoded string data.

Returns

(String) The string representation of buffer.

decodeBase64

function decodeBase64(sBase64,
nBlocksSize)

Base 64 decoding function from

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding

encodeBase64

function encodeBase64 (aBytes)

Base 64 encoding function from

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding

checkForUpdates

var checkForUpdates = function (callback)

Passes true to the callback if there are updates.  Applies updates if any.  It is safe to call startLoading while checking for updates.  It will just wait for it to finish.

function startLoading(folder,
events,
postTasks)
Begin loading a folder.
function fromBuffers(cached,
uptodate,
folder,
events,
postTasks)
Gets the archive from the cached buffer and the patch/base buffer.
function getVersion(ar)
Takes an archive and returns the version number.
function isUpdateNeeded(filename,
cachedArchive)
Reads the cached version and determines if it is up to date.
function setCached(folder,
buffer)
Sets the cached data for a folder.
function getCached(folder)
Gets the cached data for a folder.
var clearCached = function (rest)
Removes items from the cache.
function postProcess(files,
tasks)
Runs all the functions in the tasks array against all the properties on files.
function getAvalibleFileList(callback)
Gets a list of the avalible files for download.
function getMostAppropriateFile(folder,
cachedVersion,
callback)
Gets the file that should be downloaded.
EVAL_AS_JS: function (name,
data,
output)
Evaluates a script files in a special way that plays nicely with the debugger.
STRINGIFY: function (name,
data,
output)
Decode files into strings if they match the passed extionstion.
PARSE_AS_JSON: function (name,
data,
output)
Decode files into strings if they match the passed extionstion.
USE_AS_CSS: function (name,
data,
output)
Decode files into strings if they match the passed extionstion.
BASE64IFY: function (name,
data,
output)
Decode files into base64strings if they match the passed extionstion.
REMOVE_FILE_EXTS: function (name,
data,
output)
Removes file extentions.
EXPAND_FOLDERS: function (name,
data,
output)
Expands the folder structure of the files in the archive.
var FILTER
Contains post processing tasks that filter out files for other post tasks.
WITH_EXT: function (ext,
f)
A filter that calls the passed function if the name matches the passed file extention.
WITH_FILE: function (n,
f)
A filter than calls the passed function if the names match.
WITHOUT: function (re,
f)
A filter than calls the passed function if the names don’t match.
function decodeString (buffer)
Returns a string from a UTF8 encoded arraybuffer.
function decodeBase64(sBase64,
nBlocksSize)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
function encodeBase64 (aBytes)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
var checkForUpdates = function (callback)
Passes true to the callback if there are updates.
Close