<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Jaggery - Delicious Javascript</title>
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le HTML5 shim, for IE6-8 support of HTML elpreents -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le styles -->
    <link href="../css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
        body {
            padding-top: 60px;
        }
    </style>
    <link href="../css/prettify.css" rel="stylesheet">
    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="../images/favicon.ico">
    <link rel="apple-touch-icon" href="../images/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="72x72"
          href="../images/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="114x114"
          href="../images/apple-touch-icon-114x114.png">
</head>

<body>

<%
include('/includes/topnavi.jag');
%>

<div class="container-fluid" style="width: 960px; margin: auto;">
    <div class="row">
        <div class="span16">
            <div class="page-header">
                <h1>
                    Documentation
                    <small>API documentation for Jaggery.js</small>
                </h1>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="span4">
            <div class="well">
                <%
                include('/includes/navi.jag');
                %>

            </div>

        </div>
        <div class="span12">
            <div class="content" id="preail" name="preail">
                <h3>File</h3>

        <pre class="prettyprint linenums">
&lt%
    var path = "/foo.txt";
    var file = new File(path);
    file.open("r");

    var message = "";

    message = file.readAll(); 
    print(message);
    
    file.close();
%&gt
</pre>
                <%
                var fileCode = '&lt%'
                + '\n var path = "/foo.txt";'
                + '\n var file = new File(path);'
                + '\n file.open("r");'
                + '\n'
                + '\n var message = "";'
                + '\n'
                + '\n message = file.readAll()'
                + '\n print(message);'
                + '\n'
                + '\n file.close();'
                + '\n %&gt';

                var codeSnip = encodeURIComponent(fileCode);
                var urlString = '../tryitframe.jag?code='+codeSnip;

                include('/includes/tryit_but.jag');
                %>

                <br>
 <% hasMembers = false; %>
<div id="pageLinks">
<a class="navilink" href="#overview">Overview</a>
    <%if(hasMembers) {%>
<a class="navilink" href="#members">Members</a>
        <%}%>
        <%if(hasOps) {%>
<a class="navilink" href="#operations">Operations</a>
            <%}%>
</div>
<section id="overview">
    <h4>Overview</h4>
    <p class="description">The File object is meant to provide file storage/manipulation functionality.</p>

</section>

            <section id="operations">

                <h4>Operations</h4>

                <table class="clsStd operations-table">
                    <tbody>
                    <tr>
                        <th>Operation</th>
                        <th>Returns</th>
                        <th>Description</th>
                    </tr>
                    <tr>

                        <td><code>File(String filename)</code></td>
                        <td>Object</td>
                        <td>
                            <!--pre class="prettyprint">var file = new File("file:///etc/fstab");</pre>
                            <pre class="prettyprint">var file = new File("file://localhost/etc/fstab");</pre>
                            <pre class="prettyprint">var file = new File("file:///c:/WINDOWS/clock.avi");</pre-->
                            <pre class="prettyprint">var file = new File("/templates/tmp.jag");</pre>
                            <p>Takes a filename and provides a File object. (File path is relative to the Jaggery application context root)</p>
                            <!--p>If a file in your web context is referred, then use the relative path.
                                Else, specify the file system path using file URI scheme.</p-->
                        </td>

                    </tr>
                    <tr>
                        <td>
                            <code>open(r | r+ | w | w+ | a | a+)</code>
                        </td>
                        <td>None</td>
                        <td>
                        <pre class="prettyprint">
var file = new File("readme.txt");
file.open("r+");
                            </pre>
                        File can be opened for <u>read(r)</u>, <u>write(w)</u>, <u>append(a)</u>, <u>read+write(r+)</u>,
                        <u>write+read(w+)</u>, <u>append+read(a+)</u></td>
                    </tr>
                    <tr>
                        <td>
                            <code>write(Object Object)</code>
                        </td>
                        <td>None</td>
                        <td><pre class="prettyprint">var file = new File("readme.txt");
file.open("w");
file.write("Hello World!");
file.close();
                            </pre>
                            Writes the String representation of the
                            object to the file. Users can open the file for writing from the
                            start of the file or
                            for appending to the end of the file.
                            <br><br>
                            If the file is not already open for writing or appending,
                            then calling this will automatically open the file for writing
                            (overwriting the current content of the file if it exists).
                            <br><br>
                            Throws an error if the file is already open for reading.


                        </td>
                    </tr>
                    <tr>
                        <td>
                            <code>read(int numberOfCharacters)</code>
                        </td>
                        <td>String</td>
                        <td><pre class="prettyprint">var file = new File("readme.txt");
file.open("r");
var text = file.read(5);
print(text);
file.close();</pre>
                            Reads the given number of characters from the
                            file and returns a string representation of those characters. Users are
                            required to open the file for reading before reading from the file.
                            <br><br>
                            If the file is not open for either reading or writing or appending,
                            then calling this will automatically open the file for reading.
                           
                        </td>
                    </tr>
                            <tr>
                                <td>
                                    <code>getStream()</code>
                                </td>
                                <td>Stream</td>
                                <td><pre class="prettyprint">var file = new File("readme.txt");
file.open("r");
print(file.getStream());
file.close();</pre>

                                Can retrieve the input stream of a file
                                    </td>
                                    </tr>
                    <tr>
                        <td>
                            <code>readAll()</code>
                        </td>
                        <td>String</td>
                        <td><pre class="prettyprint">
var file = new File("readme.txt");
file.open("r");
print(file.readAll());
file.close();</pre>

                            Reads all the content in the file and returns
                            a string representation of the content. Users are required to open the
                            file for reading before reading from the file.
                            <br><br>
                            If the file is not open for either reading or writing or appending,
                            then calling this will automatically open the file for reading.
                            <br>

                        </td>
                    </tr>
                    <tr>
                        <td>
                            <code>close()</code>
                        </td>
                        <td>None</td>
                        <td>
<pre class="prettyprint">var file = new File("readme.txt");
file.open("r");
var x = file.readLine();
file.close();
file.open("a");
file.write("Hello world!");
file.close();</pre>   
                            Users are expected to close the file after reading, writing and appending to the file.


                        </td>
                    </tr>
                    <tr>
                        <td>
                            <code>move(string targetFileName)</code>
                        </td>
                        <td>Boolean</td>
                        <td>Move the file to the given target file. Returns True if the file was successfully moved.
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <code>saveAs(string targetLocation)</code>
                        </td>
                        <td>Boolean</td>
                        <td>Save the file to the given target file. Returns True if the file was successfully moved.
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <code>del()</code>
                        </td>
                        <td>Boolean</td>
                        <td>Deletes this file from the file system. Returns true or false depending on the success.
                        </td>
                    </tr>
                                <tr>
                                    <td>
                                        <code>getLength()</code>
                                    </td>
                                    <td>Long</td>
                                    <td>Length of the file in bytes</td>
                                </tr>
                                <tr>
                                    <td>
                                        <code>getLastModified()</code>
                                    </td>
                                    <td>String</td>
                                    <td>Last modified time of this file.</td>
                                </tr>
                                <tr>
                                    <td>
                                        <code>getName()</code>
                                    </td>
                                    <td>String</td>
                                    <td>Name of the file without the path.</td>
                                </tr>
                                <tr>
                                    <td>
                                        <code>isExists()</code>
                                    </td>
                                    <td>Boolean</td>
                                    <td>Checks whether this file actually exists. Returns True if the file exists.</td>
                                </tr>
                    </tbody>
                </table>
            </section>
            </div>
            <br>
            <br>
        </div>

    </div>
    <%
    include('/includes/footer.jag');
    %>

</div>

<!-- /container -->
<%
include('/includes/scripts.jag')
%>
	<script>	
		
		$(document).ready(function(){
        $('#file').toggleClass('active')
		$('#docs').addClass('active')
        })
	</script>
</body>
</html>