nixio.File.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>Reference</title>
  6. <link rel="stylesheet" href="../luadoc.css" type="text/css" />
  7. <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>LuaDoc</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li>
  26. <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
  27. </li>
  28. <li>
  29. <a href="../modules/luci.http.html">luci.http</a>
  30. </li>
  31. <li>
  32. <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
  33. </li>
  34. <li>
  35. <a href="../modules/luci.http.date.html">luci.http.date</a>
  36. </li>
  37. <li>
  38. <a href="../modules/luci.http.mime.html">luci.http.mime</a>
  39. </li>
  40. <li>
  41. <a href="../modules/luci.i18n.html">luci.i18n</a>
  42. </li>
  43. <li>
  44. <a href="../modules/luci.ip.html">luci.ip</a>
  45. </li>
  46. <li>
  47. <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
  48. </li>
  49. <li>
  50. <a href="../modules/luci.json.html">luci.json</a>
  51. </li>
  52. <li>
  53. <a href="../modules/luci.jsonc.html">luci.jsonc</a>
  54. </li>
  55. <li>
  56. <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
  57. </li>
  58. <li>
  59. <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
  60. </li>
  61. <li>
  62. <a href="../modules/luci.model.uci.html">luci.model.uci</a>
  63. </li>
  64. <li>
  65. <a href="../modules/luci.rpcc.html">luci.rpcc</a>
  66. </li>
  67. <li>
  68. <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
  69. </li>
  70. <li>
  71. <a href="../modules/luci.sys.html">luci.sys</a>
  72. </li>
  73. <li>
  74. <a href="../modules/luci.sys.init.html">luci.sys.init</a>
  75. </li>
  76. <li>
  77. <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
  78. </li>
  79. <li>
  80. <a href="../modules/luci.sys.net.html">luci.sys.net</a>
  81. </li>
  82. <li>
  83. <a href="../modules/luci.sys.process.html">luci.sys.process</a>
  84. </li>
  85. <li>
  86. <a href="../modules/luci.sys.user.html">luci.sys.user</a>
  87. </li>
  88. <li>
  89. <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
  90. </li>
  91. <li>
  92. <a href="../modules/luci.util.html">luci.util</a>
  93. </li>
  94. <li>
  95. <a href="../modules/nixio.html">nixio</a>
  96. </li>
  97. <li>
  98. <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
  99. </li>
  100. <li>
  101. <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
  102. </li>
  103. <li><strong>nixio.File</strong></li>
  104. <li>
  105. <a href="../modules/nixio.README.html">nixio.README</a>
  106. </li>
  107. <li>
  108. <a href="../modules/nixio.Socket.html">nixio.Socket</a>
  109. </li>
  110. <li>
  111. <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
  112. </li>
  113. <li>
  114. <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
  115. </li>
  116. <li>
  117. <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
  118. </li>
  119. <li>
  120. <a href="../modules/nixio.bin.html">nixio.bin</a>
  121. </li>
  122. <li>
  123. <a href="../modules/nixio.bit.html">nixio.bit</a>
  124. </li>
  125. <li>
  126. <a href="../modules/nixio.crypto.html">nixio.crypto</a>
  127. </li>
  128. <li>
  129. <a href="../modules/nixio.fs.html">nixio.fs</a>
  130. </li>
  131. </ul>
  132. <!-- File list -->
  133. </div><!-- id="navigation" -->
  134. <div id="content">
  135. <h1>Object Instance <code>nixio.File</code></h1>
  136. <p>
  137. Large File Object.
  138. Large file operations are supported up to 52 bits if the Lua number type is
  139. double (default).</p>
  140. <h2>Functions</h2>
  141. <table class="function_list">
  142. <tr>
  143. <td class="name" nowrap><a href="#File.close">File:close</a>&nbsp;()</td>
  144. <td class="summary">
  145. Close the file descriptor.</td>
  146. </tr>
  147. <tr>
  148. <td class="name" nowrap><a href="#File.fileno">File:fileno</a>&nbsp;()</td>
  149. <td class="summary">
  150. Get the number of the filedescriptor.</td>
  151. </tr>
  152. <tr>
  153. <td class="name" nowrap><a href="#File.lock">File:lock</a>&nbsp;(command, length)</td>
  154. <td class="summary">
  155. Apply or test a lock on the file.</td>
  156. </tr>
  157. <tr>
  158. <td class="name" nowrap><a href="#File.read">File:read</a>&nbsp;(length)</td>
  159. <td class="summary">
  160. Read from a file descriptor.</td>
  161. </tr>
  162. <tr>
  163. <td class="name" nowrap><a href="#File.seek">File:seek</a>&nbsp;(offset, whence)</td>
  164. <td class="summary">
  165. Reposition read / write offset of the file descriptor.</td>
  166. </tr>
  167. <tr>
  168. <td class="name" nowrap><a href="#File.setblocking">File:setblocking</a>&nbsp;(blocking)</td>
  169. <td class="summary">
  170. (POSIX) Set the blocking mode of the file descriptor.</td>
  171. </tr>
  172. <tr>
  173. <td class="name" nowrap><a href="#File.stat">File:stat</a>&nbsp;(field)</td>
  174. <td class="summary">
  175. Get file status and attributes.</td>
  176. </tr>
  177. <tr>
  178. <td class="name" nowrap><a href="#File.sync">File:sync</a>&nbsp;(data_only)</td>
  179. <td class="summary">
  180. Synchronizes the file with the storage device.</td>
  181. </tr>
  182. <tr>
  183. <td class="name" nowrap><a href="#File.tell">File:tell</a>&nbsp;()</td>
  184. <td class="summary">
  185. Return the current read / write offset of the file descriptor.</td>
  186. </tr>
  187. <tr>
  188. <td class="name" nowrap><a href="#File.write">File:write</a>&nbsp;(buffer, offset, length)</td>
  189. <td class="summary">
  190. Write to the file descriptor.</td>
  191. </tr>
  192. </table>
  193. <br/>
  194. <br/>
  195. <h2><a name="functions"></a>Functions</h2>
  196. <dl class="function">
  197. <dt><a name="File.close"></a><strong>File:close</strong>&nbsp;()</dt>
  198. <dd>
  199. Close the file descriptor.
  200. <h3>Return value:</h3>
  201. true
  202. </dd>
  203. <dt><a name="File.fileno"></a><strong>File:fileno</strong>&nbsp;()</dt>
  204. <dd>
  205. Get the number of the filedescriptor.
  206. <h3>Return value:</h3>
  207. file descriptor number
  208. </dd>
  209. <dt><a name="File.lock"></a><strong>File:lock</strong>&nbsp;(command, length)</dt>
  210. <dd>
  211. Apply or test a lock on the file.
  212. <h3>Parameters</h3>
  213. <ul>
  214. <li>
  215. command: Locking Command ["lock", "tlock", "ulock", "test"]
  216. </li>
  217. <li>
  218. length: Amount of Bytes to lock from current offset (optional)
  219. </li>
  220. </ul>
  221. <h3>Usage</h3>
  222. <ul>
  223. <li>This function calls lockf() on POSIX and _locking() on Windows.
  224. <li>The "lock" command is blocking, "tlock" is non-blocking,
  225. "ulock" unlocks and "test" only tests for the lock.
  226. <li>The "test" command is not available on Windows.
  227. <li>Locks are by default advisory on POSIX, but mandatory on Windows.
  228. </ul>
  229. <h3>Return value:</h3>
  230. true
  231. </dd>
  232. <dt><a name="File.read"></a><strong>File:read</strong>&nbsp;(length)</dt>
  233. <dd>
  234. Read from a file descriptor.
  235. <h3>Parameters</h3>
  236. <ul>
  237. <li>
  238. length: Amount of data to read (in Bytes).
  239. </li>
  240. </ul>
  241. <h3>Usage</h3>
  242. <ul>
  243. <li><strong>Warning:</strong> It is not guaranteed that all requested data
  244. is read at once especially when dealing with pipes.
  245. You have to check the return value - the length of the buffer actually read -
  246. or use the safe IO functions in the high-level IO utility module.
  247. <li>The length of the return buffer is limited by the (compile time)
  248. nixio buffersize which is <em>nixio.const.buffersize</em> (8192 by default).
  249. Any read request greater than that will be safely truncated to this value.
  250. </ul>
  251. <h3>Return value:</h3>
  252. buffer containing data successfully read
  253. </dd>
  254. <dt><a name="File.seek"></a><strong>File:seek</strong>&nbsp;(offset, whence)</dt>
  255. <dd>
  256. Reposition read / write offset of the file descriptor.
  257. The seek will be done either from the beginning of the file or relative
  258. to the current position or relative to the end.
  259. <h3>Parameters</h3>
  260. <ul>
  261. <li>
  262. offset: File Offset
  263. </li>
  264. <li>
  265. whence: Starting point [<strong>"set"</strong>, "cur", "end"]
  266. </li>
  267. </ul>
  268. <h3>Usage:</h3>
  269. This function calls lseek().
  270. <h3>Return value:</h3>
  271. new (absolute) offset position
  272. </dd>
  273. <dt><a name="File.setblocking"></a><strong>File:setblocking</strong>&nbsp;(blocking)</dt>
  274. <dd>
  275. (POSIX) Set the blocking mode of the file descriptor.
  276. <h3>Parameters</h3>
  277. <ul>
  278. <li>
  279. blocking: (boolean)
  280. </li>
  281. </ul>
  282. <h3>Return value:</h3>
  283. true
  284. </dd>
  285. <dt><a name="File.stat"></a><strong>File:stat</strong>&nbsp;(field)</dt>
  286. <dd>
  287. Get file status and attributes.
  288. <h3>Parameters</h3>
  289. <ul>
  290. <li>
  291. field: Only return a specific field, not the whole table (optional)
  292. </li>
  293. </ul>
  294. <h3>Usage:</h3>
  295. This function calls fstat().
  296. <h3>Return value:</h3>
  297. Table containing: <ul>
  298. <li>atime = Last access timestamp</li>
  299. <li>blksize = Blocksize (POSIX only)</li>
  300. <li>blocks = Blocks used (POSIX only)</li>
  301. <li>ctime = Creation timestamp</li>
  302. <li>dev = Device ID</li>
  303. <li>gid = Group ID</li>
  304. <li>ino = Inode</li>
  305. <li>modedec = Mode converted into a decimal number</li>
  306. <li>modestr = Mode as string as returned by <code>ls -l</code></li>
  307. <li>mtime = Last modification timestamp</li>
  308. <li>nlink = Number of links</li>
  309. <li>rdev = Device ID (if special file)</li>
  310. <li>size = Size in bytes</li>
  311. <li>type = ["reg", "dir", "chr", "blk", "fifo", "lnk", "sock"]</li>
  312. <li>uid = User ID</li>
  313. </ul>
  314. </dd>
  315. <dt><a name="File.sync"></a><strong>File:sync</strong>&nbsp;(data_only)</dt>
  316. <dd>
  317. Synchronizes the file with the storage device.
  318. Returns when the file is successfully written to the disk.
  319. <h3>Parameters</h3>
  320. <ul>
  321. <li>
  322. data_only: Do not synchronize the metadata. (optional, boolean)
  323. </li>
  324. </ul>
  325. <h3>Usage</h3>
  326. <ul>
  327. <li>This function calls fsync() when data_only equals false
  328. otherwise fdatasync(), on Windows _commit() is used instead.
  329. <li>fdatasync() is only supported by Linux and Solaris. For other systems
  330. the <em>data_only</em> parameter is ignored and fsync() is always called.
  331. </ul>
  332. <h3>Return value:</h3>
  333. true
  334. </dd>
  335. <dt><a name="File.tell"></a><strong>File:tell</strong>&nbsp;()</dt>
  336. <dd>
  337. Return the current read / write offset of the file descriptor.
  338. <h3>Usage:</h3>
  339. This function calls lseek() with offset 0 from the current position.
  340. <h3>Return value:</h3>
  341. offset position
  342. </dd>
  343. <dt><a name="File.write"></a><strong>File:write</strong>&nbsp;(buffer, offset, length)</dt>
  344. <dd>
  345. Write to the file descriptor.
  346. <h3>Parameters</h3>
  347. <ul>
  348. <li>
  349. buffer: Buffer holding the data to be written.
  350. </li>
  351. <li>
  352. offset: Offset to start reading the buffer from. (optional)
  353. </li>
  354. <li>
  355. length: Length of chunk to read from the buffer. (optional)
  356. </li>
  357. </ul>
  358. <h3>Usage</h3>
  359. <ul>
  360. <li><strong>Warning:</strong> It is not guaranteed that all data
  361. in the buffer is written at once especially when dealing with pipes.
  362. You have to check the return value - the number of bytes actually written -
  363. or use the safe IO functions in the high-level IO utility module.
  364. <li>Unlike standard Lua indexing the lowest offset and default is 0.
  365. </ul>
  366. <h3>Return value:</h3>
  367. number of bytes written
  368. </dd>
  369. </dl>
  370. </div> <!-- id="content" -->
  371. </div> <!-- id="main" -->
  372. <div id="about">
  373. <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
  374. </div> <!-- id="about" -->
  375. </div> <!-- id="container" -->
  376. </body>
  377. </html>