Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Donaldson committed Jul 12, 2012
1 parent 1fea249 commit c448332
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 48 deletions.
178 changes: 144 additions & 34 deletions src/js/phantom/FileSystem.hx
Expand Up @@ -2,39 +2,149 @@ package js.phantom;

@:native("require('fs')");
extern class FileSystem {
//Read-only properties
public static var separator(default,null):String; // is the path separator (forward slash or backslash, depending on the operating system).
public static var workingDirectory(default,null):String; // is the current working directory.

//Query functions
public static function list(path):Array<String>; // returns the list of all the names of all the files in a specified path.
public static function absolute(path):String // returns the absolute path starting from the root file system, resolved from the current working directory.
public static function exists(path):Bool // returns true if a file or a directory exists.
public static function isDirectory(path):Bool // returns true if the specified path is a directory.
public static function isFile(path):Bool // returns true if the specified path is a file.
public static function isAbsolute(path):Bool // returns true if the specified path is an absolute path.
public static function isExecutable(path):Bool // returns true if the specified file can be executed.
public static function isReadable(path):Bool // returns true if a file or a directory is readable.
public static function isWritable(path):Bool // returns true if a file or a directory is writeable.
public static function isLink(path):Bool // returns true if the specified path is a symbolic link.
public static function readLink(path):String // returns the target of a symbolic link.

//Directory-related functions:
public static function changeWorkingDirectory(path):Void; // changes the current working directory to the specified path.
public static function makeDirectory(path):Void; // creates a new directory.
public static function makeTree(path):Void; // creates a directory including any missing parent directories.
public static function removeDirectory(path):Void; // removes a directory if it is empty
public static function removeTree(path):Void; // removes the specified path, regardless of whether it is a file or a directory.
public static function copyTree(source, destination):Void; // copies the entire files from a source path to the destination path.

//File-related functions:
public static function open(path, mode):StreamObject; // returns a stream object representing the stream interface to the specified file (mode can be r for read, w for write, or a for append).
public static function read(path):String; // returns the entire content of a file.
public static function write(path, content, mode):Void; // writes content to a file (mode can be w for write or a for append).
public static function size(path):Int; // returns the size (in bytes) of the file specified by the path.
public static function remove(path):Void; // removes the file specified by the path.
public static function copy(source, destination):Void; // copies a file to another.
public static function move(source, destination):Void; // movies a file to another, effectively renaming it.
public static function touch(path):Void; // touches a file (i.e. changes its access timestamp).
//Read-only properties

/**
is the path separator (forward slash or backslash, depending on the operating system).
**/
public static var separator(default,null):String;

/**
is the current working directory.
**/
public static var workingDirectory(default,null):String;

//Query functions

/**
returns the list of all the names of all the files in a specified path.
**/
public static function list(path):Array<String>;

/**
returns the absolute path starting from the root file system, resolved
from the current working directory.
**/
public static function absolute(path):String;

/**
returns true if a file or a directory exists.
**/
public static function exists(path):Bool;

/**
returns true if the specified path is a directory.
**/
public static function isDirectory(path):Bool;

/**
returns true if the specified path is a file.
**/
public static function isFile(path):Bool;

/**
returns true if the specified path is an absolute path.
**/
public static function isAbsolute(path):Bool;

/**
returns true if the specified file can be executed.
**/
public static function isExecutable(path):Bool;

/**
returns true if a file or a directory is readable.
**/
public static function isReadable(path):Bool;

/**
returns true if a file or a directory is writeable.
**/
public static function isWritable(path):Bool;

/**
returns true if the specified path is a symbolic link.
**/
public static function isLink(path):Bool;

/**
returns the target of a symbolic link.
**/
public static function readLink(path):String;

//Directory-related functions:
/**
changes the current working directory to the specified path.
**/
public static function changeWorkingDirectory(path):Void;

/**
creates a new directory.
**/
public static function makeDirectory(path):Void;

/**
creates a directory including any missing parent directories.
**/
public static function makeTree(path):Void;

/**
removes a directory if it is empty
**/
public static function removeDirectory(path):Void;

/**
removes the specified path, regardless of whether it is a file or a
directory.
**/
public static function removeTree(path):Void;

/**
copies the entire files from a source path to the destination path.
**/
public static function copyTree(source, destination):Void;

//File-related functions:
/**
returns a stream object representing the stream interface to the
specified file (mode can be r for read, w for write, or a for append).
**/
public static function open(path, mode):StreamObject;

/**
returns the entire content of a file.
**/
public static function read(path):String;

/**
writes content to a file (mode can be w for write or a for append).
**/
public static function write(path, content, mode):Void;

/**
returns the size (in bytes) of the file specified by the path.
**/
public static function size(path):Int;

/**
removes the file specified by the path.
**/
public static function remove(path):Void;

/**
copies a file to another.
**/
public static function copy(source, destination):Void;

/**
movies a file to another, effectively renaming it.
**/
public static function move(source, destination):Void;

/**
touches a file (i.e. changes its access timestamp).
**/
public static function touch(path):Void;

}
43 changes: 37 additions & 6 deletions src/js/phantom/PhantomJs.hx
Expand Up @@ -2,13 +2,44 @@ package js.phantom;

@:native("phantom")
extern class PhantomJs {
public static var args:Array<String>; // (array) This read-only property is an array of the arguments passed to the script. Deprecated: Please use system.args from the System module.
public static var libraryPath:String; // (string) This property stores the path which is used by injectJs function to resolve the script name. Initially it is set to the location of the script invoked by PhantomJS.
public static var scriptName:String; //(string) This read-only property stores the name of the invoked script file. Deprecated: Please use system.args[0] from the System module.
public static var version:{major:Int, minor:Int, patch:Int}; // (object) This read-only property holds PhantomJS version. Example value: { major:1, minor:0, patch:0 }.
/**
This read-only property is an array of the arguments passed to
the script. Deprecated: Please use system.args from the System module.
**/
public static var args:Array<String>;

public static function exit(returnValue:Dynamic); // Exits the program with the specified return value. If no return value is specified, it is set to 0.
public static function injectJs(filename:String):Bool; // Injects external script code from the specified file. If the file can not be found in the current directory, libraryPath is used for additional look up. This function returns true if injection is successful, otherwise it returns false.
/**
This property stores the path which is used by injectJs
function to resolve the script name. Initially it is set to the location
of the script invoked by PhantomJS.
**/
public static var libraryPath:String;

/**
This read-only property stores the name of the invoked script file.
Deprecated: Please use system.args[0] from the System module.
**/
public static var scriptName:String;

/**
This read-only property holds PhantomJS version. Example value: {
major:1, minor:0, patch:0 }.
**/
public static var version:{major:Int, minor:Int, patch:Int};

/**
Exits the program with the specified return value. If no return value is
specified, it is set to 0.
**/
public static function exit(returnValue:Dynamic);

/**
Injects external script code from the specified file. If the file can
not be found in the current directory, libraryPath is used for
additional look up. This function returns true if injection is
successful, otherwise it returns false.
**/
public static function injectJs(filename:String):Bool;

}

Expand Down
41 changes: 33 additions & 8 deletions src/js/phantom/StreamObject.hx
@@ -1,13 +1,38 @@
package js.phantom;

/**
A stream object returned from the open() function
**/
class StreamObject{
//A stream object returned from the open() function has the following functions:

public function read():String; // returns the content of the stream.
public function write(data):Void; // writes the string to the stream.
public function readLine():String; // reads only a line from the stream and return it.
public function writeLine(data):Void; // writes the data as a line to the stream.
public function flush():Void; // flushes all pending input output.
public function close():Void; // completes the stream operation.
/**
returns the content of the stream.
**/
public function read():String;

r}
/**
writes the string to the stream.
**/
public function write(data):Void;

/**
reads only a line from the stream and return it.
**/
public function readLine():String;

/**
writes the data as a line to the stream.
**/
public function writeLine(data):Void;

/**
flushes all pending input output.
**/
public function flush():Void;

/**
completes the stream operation.
**/
public function close():Void;

}

0 comments on commit c448332

Please sign in to comment.