5 <title>JSDoc: Class: fs</title>
7 <script src="scripts/prettify/prettify.js"> </script>
8 <script src="scripts/prettify/lang-css.js"> </script>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
12 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13 <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
20 <h1 class="page-title">Class: fs</h1>
31 <h2><span class="attribs"><span class="type-signature"></span></span>
32 <span class="ancestors"><a href="LuCI.html">LuCI</a>.</span>fs</h2>
34 <div class="class-description"><p>Provides high level utilities to wrap file system related RPC calls.
35 To import the class in views, use <code>'require fs'</code>, to import it in
36 external JavaScript, use <code>L.require("fs").then(...)</code>.</p></div>
42 <div class="container-overview">
87 <dt class="tag-source">Source:</dt>
88 <dd class="tag-source"><ul class="dummy"><li>
89 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line111">line 111</a>
137 <h3 class="subsection-title">Methods</h3>
145 <h4 class="name" id="exec"><span class="type-signature"></span>exec<span class="signature">(command, params<span class="signature-attributes">opt</span>, env<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<<a href="LuCI.fs.html#.FileExecResult">LuCI.fs.FileExecResult</a>>}</span></h4>
152 <div class="description">
153 <p>Execute the specified command, optionally passing params and
154 environment variables.</p>
155 <p>Note: The <code>command</code> must be either the path to an executable,
156 or a basename without arguments in which case it will be searched
157 in $PATH. If specified, the values given in <code>params</code> will be passed
158 as arguments to the command.</p>
159 <p>The key/value pairs in the optional <code>env</code> table are translated to
160 <code>setenv()</code> calls prior to running the command.</p>
174 <table class="params">
189 <th class="last">Description</th>
198 <td class="name"><code>command</code></td>
204 <span class="param-type">string</span>
211 <td class="attributes">
222 <td class="description last"><p>The command to invoke.</p></td>
229 <td class="name"><code>params</code></td>
235 <span class="param-type">Array.<string></span>
242 <td class="attributes">
255 <td class="description last"><p>The arguments to pass to the command.</p></td>
262 <td class="name"><code>env</code></td>
268 <span class="param-type">Object.<string, string></span>
275 <td class="attributes">
288 <td class="description last"><p>Environment variables to set.</p></td>
327 <dt class="tag-source">Source:</dt>
328 <dd class="tag-source"><ul class="dummy"><li>
329 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line232">line 232</a>
357 <div class="param-desc">
358 <p>Returns a promise resolving to an object describing the execution
359 results or rejecting with an error stating the failure reason.</p>
370 <span class="param-type">Promise.<<a href="LuCI.fs.html#.FileExecResult">LuCI.fs.FileExecResult</a>></span>
388 <h4 class="name" id="lines"><span class="type-signature"></span>lines<span class="signature">(path)</span><span class="type-signature"> → {Promise.<Array.<string>>}</span></h4>
395 <div class="description">
396 <p>Read the contents of the given file, split it into lines, trim
397 leading and trailing white space of each line and return the
399 <p>This function is guaranteed to not reject its promises, on failure,
400 an empty array will be returned.</p>
414 <table class="params">
427 <th class="last">Description</th>
436 <td class="name"><code>path</code></td>
442 <span class="param-type">string</span>
452 <td class="description last"><p>The file path to read.</p></td>
491 <dt class="tag-source">Source:</dt>
492 <dd class="tag-source"><ul class="dummy"><li>
493 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line281">line 281</a>
521 <div class="param-desc">
522 <p>Returns a promise resolving to an array containing the stripped lines
523 of the given file or <code>[]</code> on failure.</p>
534 <span class="param-type">Promise.<Array.<string>></span>
552 <h4 class="name" id="list"><span class="type-signature"></span>list<span class="signature">(path)</span><span class="type-signature"> → {Promise.<Array.<<a href="LuCI.fs.html#.FileStatEntry">LuCI.fs.FileStatEntry</a>>>}</span></h4>
559 <div class="description">
560 <p>Obtains a listing of the specified directory.</p>
574 <table class="params">
587 <th class="last">Description</th>
596 <td class="name"><code>path</code></td>
602 <span class="param-type">string</span>
612 <td class="description last"><p>The directory path to list.</p></td>
651 <dt class="tag-source">Source:</dt>
652 <dd class="tag-source"><ul class="dummy"><li>
653 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line132">line 132</a>
681 <div class="param-desc">
682 <p>Returns a promise resolving to an array of stat detail objects or
683 rejecting with an error stating the failure reason.</p>
694 <span class="param-type">Promise.<Array.<<a href="LuCI.fs.html#.FileStatEntry">LuCI.fs.FileStatEntry</a>>></span>
712 <h4 class="name" id="read"><span class="type-signature"></span>read<span class="signature">(path)</span><span class="type-signature"> → {Promise.<string>}</span></h4>
719 <div class="description">
720 <p>Read the contents of the given file and return them.
721 Note: this function is unsuitable for obtaining binary data.</p>
735 <table class="params">
748 <th class="last">Description</th>
757 <td class="name"><code>path</code></td>
763 <span class="param-type">string</span>
773 <td class="description last"><p>The file path to read.</p></td>
812 <dt class="tag-source">Source:</dt>
813 <dd class="tag-source"><ul class="dummy"><li>
814 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line161">line 161</a>
842 <div class="param-desc">
843 <p>Returns a promise resolving to a string containing the file contents or
844 rejecting with an error stating the failure reason.</p>
855 <span class="param-type">Promise.<string></span>
873 <h4 class="name" id="remove"><span class="type-signature"></span>remove<span class="signature">(The)</span><span class="type-signature"> → {Promise.<number>}</span></h4>
880 <div class="description">
881 <p>Unlink the given file.</p>
895 <table class="params">
908 <th class="last">Description</th>
917 <td class="name"><code>The</code></td>
923 <span class="param-type">string</span>
933 <td class="description last"><p>file path to remove.</p></td>
972 <dt class="tag-source">Source:</dt>
973 <dd class="tag-source"><ul class="dummy"><li>
974 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line203">line 203</a>
1002 <div class="param-desc">
1003 <p>Returns a promise resolving to <code>0</code> or rejecting with an error stating
1004 the failure reason.</p>
1015 <span class="param-type">Promise.<number></span>
1033 <h4 class="name" id="stat"><span class="type-signature"></span>stat<span class="signature">(path)</span><span class="type-signature"> → {Promise.<<a href="LuCI.fs.html#.FileStatEntry">LuCI.fs.FileStatEntry</a>>}</span></h4>
1040 <div class="description">
1041 <p>Return file stat information on the specified path.</p>
1052 <h5>Parameters:</h5>
1055 <table class="params">
1068 <th class="last">Description</th>
1077 <td class="name"><code>path</code></td>
1083 <span class="param-type">string</span>
1093 <td class="description last"><p>The filesystem path to stat.</p></td>
1105 <dl class="details">
1132 <dt class="tag-source">Source:</dt>
1133 <dd class="tag-source"><ul class="dummy"><li>
1134 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line146">line 146</a>
1162 <div class="param-desc">
1163 <p>Returns a promise resolving to a stat detail object or
1164 rejecting with an error stating the failure reason.</p>
1175 <span class="param-type">Promise.<<a href="LuCI.fs.html#.FileStatEntry">LuCI.fs.FileStatEntry</a>></span>
1193 <h4 class="name" id="trimmed"><span class="type-signature"></span>trimmed<span class="signature">(path)</span><span class="type-signature"> → {Promise.<string>}</span></h4>
1200 <div class="description">
1201 <p>Read the contents of the given file, trim leading and trailing white
1202 space and return the trimmed result. In case of errors, return an empty
1204 <p>Note: this function is useful to read single-value files in <code>/sys</code>
1205 or <code>/proc</code>.</p>
1206 <p>This function is guaranteed to not reject its promises, on failure,
1207 an empty string will be returned.</p>
1218 <h5>Parameters:</h5>
1221 <table class="params">
1234 <th class="last">Description</th>
1243 <td class="name"><code>path</code></td>
1249 <span class="param-type">string</span>
1259 <td class="description last"><p>The file path to read.</p></td>
1271 <dl class="details">
1298 <dt class="tag-source">Source:</dt>
1299 <dd class="tag-source"><ul class="dummy"><li>
1300 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line260">line 260</a>
1328 <div class="param-desc">
1329 <p>Returns a promise resolving to the file contents or the empty string
1341 <span class="param-type">Promise.<string></span>
1359 <h4 class="name" id="write"><span class="type-signature"></span>write<span class="signature">(path, data<span class="signature-attributes">opt</span>, mode<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<number>}</span></h4>
1366 <div class="description">
1367 <p>Write the given data to the specified file path.
1368 If the specified file path does not exist, it will be created, given
1369 sufficient permissions.</p>
1370 <p>Note: <code>data</code> will be converted to a string using <code>String(data)</code> or to
1371 <code>''</code> when it is <code>null</code>.</p>
1382 <h5>Parameters:</h5>
1385 <table class="params">
1400 <th class="last">Description</th>
1409 <td class="name"><code>path</code></td>
1415 <span class="param-type">string</span>
1422 <td class="attributes">
1433 <td class="description last"><p>The file path to write to.</p></td>
1440 <td class="name"><code>data</code></td>
1446 <span class="param-type">*</span>
1453 <td class="attributes">
1466 <td class="description last"><p>The file data to write. If it is null, it will be set to an empty
1474 <td class="name"><code>mode</code></td>
1480 <span class="param-type">number</span>
1487 <td class="attributes">
1500 <td class="description last"><p>The permissions to use on file creation. Default is 420 (0644).</p></td>
1512 <dl class="details">
1539 <dt class="tag-source">Source:</dt>
1540 <dd class="tag-source"><ul class="dummy"><li>
1541 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line187">line 187</a>
1569 <div class="param-desc">
1570 <p>Returns a promise resolving to <code>0</code> or rejecting with an error stating
1571 the failure reason.</p>
1582 <span class="param-type">Promise.<number></span>
1598 <h3 class="subsection-title">Type Definitions</h3>
1602 <h4 class="name" id=".FileExecResult">FileExecResult</h4>
1613 <span class="param-type">Object</span>
1623 <h5 class="subsection-title">Properties:</h5>
1627 <table class="props">
1642 <th class="last">Description</th>
1651 <td class="name"><code>code</code></td>
1657 <span class="param-type">number</span>
1664 <td class="attributes">
1673 <td class="description last"><p>The exit code of the invoked command</p></td>
1680 <td class="name"><code>stdout</code></td>
1686 <span class="param-type">string</span>
1693 <td class="attributes">
1704 <td class="description last"><p>The stdout produced by the command, if any</p></td>
1711 <td class="name"><code>stderr</code></td>
1717 <span class="param-type">string</span>
1724 <td class="attributes">
1735 <td class="description last"><p>The stderr produced by the command, if any</p></td>
1745 <dl class="details">
1772 <dt class="tag-source">Source:</dt>
1773 <dd class="tag-source"><ul class="dummy"><li>
1774 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line20">line 20</a>
1792 <h4 class="name" id=".FileStatEntry">FileStatEntry</h4>
1803 <span class="param-type">Object</span>
1813 <h5 class="subsection-title">Properties:</h5>
1817 <table class="props">
1830 <th class="last">Description</th>
1839 <td class="name"><code>name</code></td>
1845 <span class="param-type">string</span>
1855 <td class="description last"><p>Name of the directory entry</p></td>
1862 <td class="name"><code>type</code></td>
1868 <span class="param-type">string</span>
1878 <td class="description last"><p>Type of the entry, one of <code>block</code>, <code>char</code>, <code>directory</code>, <code>fifo</code>, <code>symlink</code>, <code>file</code>, <code>socket</code> or <code>unknown</code></p></td>
1885 <td class="name"><code>size</code></td>
1891 <span class="param-type">number</span>
1901 <td class="description last"><p>Size in bytes</p></td>
1908 <td class="name"><code>mode</code></td>
1914 <span class="param-type">number</span>
1924 <td class="description last"><p>Access permissions</p></td>
1931 <td class="name"><code>atime</code></td>
1937 <span class="param-type">number</span>
1947 <td class="description last"><p>Last access time in seconds since epoch</p></td>
1954 <td class="name"><code>mtime</code></td>
1960 <span class="param-type">number</span>
1970 <td class="description last"><p>Last modification time in seconds since epoch</p></td>
1977 <td class="name"><code>ctime</code></td>
1983 <span class="param-type">number</span>
1993 <td class="description last"><p>Last change time in seconds since epoch</p></td>
2000 <td class="name"><code>inode</code></td>
2006 <span class="param-type">number</span>
2016 <td class="description last"><p>Inode number</p></td>
2023 <td class="name"><code>uid</code></td>
2029 <span class="param-type">number</span>
2039 <td class="description last"><p>Numeric owner id</p></td>
2046 <td class="name"><code>gid</code></td>
2052 <span class="param-type">number</span>
2062 <td class="description last"><p>Numeric group id</p></td>
2072 <dl class="details">
2099 <dt class="tag-source">Source:</dt>
2100 <dd class="tag-source"><ul class="dummy"><li>
2101 <a href="fs.js.html">fs.js</a>, <a href="fs.js.html#line4">line 4</a>
2131 <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="LuCI.html">LuCI</a></li><li><a href="LuCI.Class.html">Class</a></li><li><a href="LuCI.dom.html">dom</a></li><li><a href="LuCI.fs.html">fs</a></li><li><a href="LuCI.Headers.html">Headers</a></li><li><a href="LuCI.Network.html">Network</a></li><li><a href="LuCI.Network.Device.html">Device</a></li><li><a href="LuCI.Network.Hosts.html">Hosts</a></li><li><a href="LuCI.Network.Protocol.html">Protocol</a></li><li><a href="LuCI.Network.WifiDevice.html">WifiDevice</a></li><li><a href="LuCI.Network.WifiNetwork.html">WifiNetwork</a></li><li><a href="LuCI.Poll.html">Poll</a></li><li><a href="LuCI.Request.html">Request</a></li><li><a href="LuCI.Request.poll.html">poll</a></li><li><a href="LuCI.Response.html">Response</a></li><li><a href="LuCI.rpc.html">rpc</a></li><li><a href="LuCI.uci.html">uci</a></li><li><a href="LuCI.view.html">view</a></li><li><a href="LuCI.XHR.html">XHR</a></li></ul>
2137 Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Tue Nov 05 2019 09:33:05 GMT+0100 (Central European Standard Time)
2140 <script> prettyPrint(); </script>
2141 <script src="scripts/linenumber.js"> </script>