Jaxer.File

Utility object for simple filesystem access.

Constructor

var file = new Jaxer.File(path);

Creates a new instance for performing filesystem file operations.

Properties

  • Jaxer.File.EOF
  • Checks 'end of file' status and returns boolean to indicate whether the end of file has been reached. This function takes no arguments but needs an open read mode filehandle.

  • Jaxer.File.ext
  • Returns the extension of the file object.

  • Jaxer.File.pos
  • Returns the current byte position in the referenced file. This method is only applicable when using the File.read() method. If used with the File.readline() method it will return the internal read ahead buffer position, which is unlikely to be what was expected.

  • Jaxer.File.size
  • Returns the size in bytes of the referenced file system object as reported by the OS..

    Methods

  • Jaxer.File.prototype.clone();
  • none

    <Jaxer.File>

    Return a new instance of a JSLib File object referencing the same path.

  • Jaxer.File.prototype.close();
  • none

    null

    Closes an open file stream.

  • Jaxer.File.prototype.copy(path);
  • <String> path - the path to copy the file to.

    null

    Copy to file to another location.

    var p='/tmp/foo.dat';
    var f=new Jaxer.File(p);
    f.copy("/tmp/foo_copy.dat");
  • Jaxer.File.prototype.create();
  • none

    null

    Creates a new file under the referenced path of the object.

  • Jaxer.File.prototype.createUnique();
  • none

    null

    Creates a new unique file under the referenced path of the object.

  • Jaxer.File.prototype.open(mode, permission);
    • <String> mode - an argument of string 'w', 'a', 'r', 'b'
    • <permission> permission - a number containing the unix style chmod value for the permissions

    null

    Opens the file for reading or writing. The provided file mode can be one or two characters the using 'rb','ab','wb' will cause the file to be opened in binary safe mode. NOTE: This implementation doesn't support file locking so will allow multiple open handles to the same file.

  • Jaxer.File.prototype.read(size);
  • <Number> size - Number of bytes to read

    Either a string or array of bytes depending on 'r' or 'rb' mode.

    Reads a file (that's already been opened) and returns its contents. Returns a null on failure.

  • Jaxer.File.prototype.readAllLines();
  • none

    String

    Returns an array of individual lines read from the file on success, throws an Exception on failure.

  • Jaxer.File.prototype.readline();
  • none

    String

    Reads a single line from an open file, takes no arguments but needs an open read mode filehandle returns string containing the data read on success, null on failure.

  • Jaxer.File.prototype.remove();
  • none

    null

    Removes the referenced file object from the file system. Throws an exception is the action fails.

  • Jaxer.File.prototype.truncate();
  • none

    null

    Truncates the file. Throws an exception if the action fails.

  • Jaxer.File.prototype.write(data);
  • <Array> data - Either a String for 'w' or an array of bytes for 'wb'

    null

    Write provided data to a file.

    var p='/tmp/foo.dat';
    var f=new Jaxer.File(p);
    f.open('w');
    f.write("some data to be written");
    f.close();