This repository has been archived by the owner. It is now read-only.

File IO

Joshua Strobl edited this page Aug 13, 2014 · 6 revisions

This page covers the functions that are actually used to create, update, read, delete and replicate files in Metis.

Some Quick Notes

Success and Error Codes

Both the server and client-side implementations of Metis provide success and/or error codes (unless stated otherwise, like reading, updating, etc.). These success and error codes can be found here and are in the following form:

Javascript

{
	"success" : "0.00"
}
{
	"error" : 2.05
}

PHP

array("success" => "0.00")
array("error" => 2.05)

File Arrays and Objects

When we return a list of files and their contents (or success codes, error codes, etc. depending on the action), we provide an array (or Object) of key / value pairs, where the keys are file names and values are the cooresponding content. Example below:

Javascript

{
	"ExampleFile" : {
		"hello world" : "I am content!"
	}
}

PHP

array(
	"ExampleFile" => array(
		"hello world" => "I am content!"
	)
)

Asynchronous and Synchronous IO

Javascript

All function calls to Metis via Javascript are asynchronous, meaning the action will happen and will let the rest of your script do stuff while we do file IO in the backend. You can optionally add a callback (as we'll describe later) to be called when the IO is done.

Whenever using a Metis function in Javascript, remember to do something like

	metis.file.FunctionYouWantToUse();

PHP

All function calls to Metis via PHP are synchronous, meaning the action will happen and we will wait for a response until continuing throughout the script. The synchronous nature in our PHP system is a limitation of PHP (no concurrency model).

Whenever using a Metis function in PHP, remember to do something like:

    $metis->theFunctionYouWantToUse();

File Hashing

All files stored in Metis on the server (PHP) are saved as a hash form for obfuscation (on the server). You can see the expected file name by using fileHashing() function.

Core Functions

Javascript

Creating and Updating Files

metis.file.Create(
	{
		"nodeData" : nodeDataDefined (string),
		"files" : files (string or array),
		"contentOrDestinationNodes" : Object,
		"callback" : Function [Optional]
	} 
)

Creates files in the specified nodeData (Node Groups (+Nodes), independent Nodes, etc.), each file with the contentOrDestinationNodes.

Returns cooresponding success and/or error codes to the optional callback.

metis.file.Update(
	{
		"nodeData" : nodeDataDefined (string),
		"files" : files (string or array),
		"append" : Boolean (defaults to true),
		"contentOrDestinationNodes" : Object,
		"callback" : Function [Optional]
	} 
)

Updates files in the specified nodeData (Node Groups (+Nodes), independent Nodes, etc.), each file with the contentOrDestinationNodes. Appended to existing file (if exists), if true, otherwise (false) it overwrites.

Returns cooresponding updated content and/or error codes to the optional callback.

Reading Files

metis.file.Read(
	{
		"nodeData" : nodeDataDefined (string),
		"files" : files (string or array),
		"callback" : Function [Optional]
	}
)

Reads files from specified nodeData (Node Groups (+Nodes), independent Nodes, etc.).

Returns cooresponding content (already parsed into Objects) and/or error codes to the optional callback.

Checking If A File Exists

metis.file.Exists(
	{
		"nodeData" : nodeDataDefined (string),
		"files" : files (string or array),
		"callback" : Function
	}
)

Checks if a file exists locally.

Returns cooresponding boolean value to the optional callback.

Delete One, Multiple, Or All Files

metis.file.Delete(
	{
		"nodeData" : nodeDataDefined (string),
		"files" : files (string or array),
		"callback" : Function
	}
)

Deletes the files provided from the device (and if connected to a server, from there as well).

Returns cooresponding success and/or error codes to the optional callback.

metis.file.ClearAll()(
	{
		"nodeData" : nodeDataDefined (string),
		"files" : files (string or array)
	}
)

Deletes all files stored on the device via Metis (as in only deletes the files Metis has control over). Does not delete all files from a particular Node Cluster

PHP

Creating and Updating Files

$metis->createJsonFile(
	nodeData (string or array / object),
	files (string or array),
	fileContent (array  object)
)

Creates files in the specified nodeDataDefined (Node Groups (+Nodes), independent Nodes, etc.), each file with the fileContent.

Returns cooresponding success and/or error codes.

$metis->updateJsonFile(
	nodeData (string or array / object),
	files (string or array),
	fileContent (array  object)
	append (boolean)
)

Updates files in the specified nodeData (Node Groups (+Nodes), independent Nodes, etc.), each file with the contentOrDestinationNodes. Appended to existing file (if exists), if true, otherwise (false) it overwrites.

Returns cooresponding updated content and/or error codes to the optional callback.

Reading and Decoding Files

$metis->readJsonFile(
	nodeData (string or array / object),
	files (string or array)
)

Reads files from specified nodeData (Node Groups (+Nodes), independent Nodes, etc.).

Returns cooresponding content (as a string, needs to be converted into a multi-dimensional array with decodeJsonFile) and/or error codes to the optional callback.

$metis->decodeJsonFile(
	fileContent (string)
)

Decodes the JSON into a multi-dimensional array. This function is the same as calling json_decode(JSON, true).

Returns multi-dimensional array or an error code.

Checking if a file exists

$metis->fileExists(
	nodeData (string or array / object),
	files (string or array)
)

Checks if the file(s) exists in the appropriate nodes (or if using TS / JS and in headless mode, then only locally)

Return JSON of multi-dimensional array, where each file is a key, with a boolean value.

Replication

$metis->fileExists(
	nodeData (string or array),
	contentOrDestinationNodes (string or array),
	files (array)
)

Replication functionality that replicates files from a source (Node Group, Nodes within Node Groups, independent Nodes, etc.) to destination(s).

Returns success ("0.00") or an error code.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.