asyncfile.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/asyncfile</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/asyncfile</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li>
  50. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  51. </li>
  52. <li>
  53. <details open>
  54. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  55. <ul class="simple simple-toc-section">
  56. <li><a class="reference" href="#AsyncFile" title="AsyncFile = ref object">AsyncFile</a></li>
  57. </ul>
  58. </details>
  59. </li>
  60. <li>
  61. <details open>
  62. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  63. <ul class="simple simple-toc-section">
  64. <ul class="simple nested-toc-section">close
  65. <li><a class="reference" href="#close%2CAsyncFile" title="close(f: AsyncFile)">close(f: AsyncFile)</a></li>
  66. </ul>
  67. <ul class="simple nested-toc-section">getFilePos
  68. <li><a class="reference" href="#getFilePos%2CAsyncFile" title="getFilePos(f: AsyncFile): int64">getFilePos(f: AsyncFile): int64</a></li>
  69. </ul>
  70. <ul class="simple nested-toc-section">getFileSize
  71. <li><a class="reference" href="#getFileSize%2CAsyncFile" title="getFileSize(f: AsyncFile): int64">getFileSize(f: AsyncFile): int64</a></li>
  72. </ul>
  73. <ul class="simple nested-toc-section">newAsyncFile
  74. <li><a class="reference" href="#newAsyncFile%2CAsyncFD" title="newAsyncFile(fd: AsyncFD): AsyncFile">newAsyncFile(fd: AsyncFD): AsyncFile</a></li>
  75. </ul>
  76. <ul class="simple nested-toc-section">openAsync
  77. <li><a class="reference" href="#openAsync%2Cstring" title="openAsync(filename: string; mode = fmRead): AsyncFile">openAsync(filename: string; mode = fmRead): AsyncFile</a></li>
  78. </ul>
  79. <ul class="simple nested-toc-section">read
  80. <li><a class="reference" href="#read%2CAsyncFile%2Cint" title="read(f: AsyncFile; size: int): Future[string]">read(f: AsyncFile; size: int): Future[string]</a></li>
  81. </ul>
  82. <ul class="simple nested-toc-section">readAll
  83. <li><a class="reference" href="#readAll%2CAsyncFile" title="readAll(f: AsyncFile): Future[string]">readAll(f: AsyncFile): Future[string]</a></li>
  84. </ul>
  85. <ul class="simple nested-toc-section">readBuffer
  86. <li><a class="reference" href="#readBuffer%2CAsyncFile%2Cpointer%2Cint" title="readBuffer(f: AsyncFile; buf: pointer; size: int): Future[int]">readBuffer(f: AsyncFile; buf: pointer; size: int): Future[int]</a></li>
  87. </ul>
  88. <ul class="simple nested-toc-section">readLine
  89. <li><a class="reference" href="#readLine%2CAsyncFile" title="readLine(f: AsyncFile): Future[string]">readLine(f: AsyncFile): Future[string]</a></li>
  90. </ul>
  91. <ul class="simple nested-toc-section">readToStream
  92. <li><a class="reference" href="#readToStream%2CAsyncFile%2CFutureStream%5Bstring%5D" title="readToStream(f: AsyncFile; fs: FutureStream[string]): owned(Future[void])">readToStream(f: AsyncFile; fs: FutureStream[string]): owned(Future[void])</a></li>
  93. </ul>
  94. <ul class="simple nested-toc-section">setFilePos
  95. <li><a class="reference" href="#setFilePos%2CAsyncFile%2Cint64" title="setFilePos(f: AsyncFile; pos: int64)">setFilePos(f: AsyncFile; pos: int64)</a></li>
  96. </ul>
  97. <ul class="simple nested-toc-section">setFileSize
  98. <li><a class="reference" href="#setFileSize%2CAsyncFile%2Cint64" title="setFileSize(f: AsyncFile; length: int64)">setFileSize(f: AsyncFile; length: int64)</a></li>
  99. </ul>
  100. <ul class="simple nested-toc-section">write
  101. <li><a class="reference" href="#write%2CAsyncFile%2Cstring" title="write(f: AsyncFile; data: string): Future[void]">write(f: AsyncFile; data: string): Future[void]</a></li>
  102. </ul>
  103. <ul class="simple nested-toc-section">writeBuffer
  104. <li><a class="reference" href="#writeBuffer%2CAsyncFile%2Cpointer%2Cint" title="writeBuffer(f: AsyncFile; buf: pointer; size: int): Future[void]">writeBuffer(f: AsyncFile; buf: pointer; size: int): Future[void]</a></li>
  105. </ul>
  106. <ul class="simple nested-toc-section">writeFromStream
  107. <li><a class="reference" href="#writeFromStream%2CAsyncFile%2CFutureStream%5Bstring%5D" title="writeFromStream(f: AsyncFile; fs: FutureStream[string]): owned(Future[void])">writeFromStream(f: AsyncFile; fs: FutureStream[string]): owned(Future[void])</a></li>
  108. </ul>
  109. </ul>
  110. </details>
  111. </li>
  112. </ul>
  113. </div>
  114. <div class="nine columns" id="content">
  115. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  116. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  117. <div id="tocRoot"></div>
  118. <p class="module-desc"><p>This module implements asynchronous file reading and writing.</p>
  119. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">asyncfile</span><span class="Punctuation">,</span> <span class="Identifier">asyncdispatch</span><span class="Punctuation">,</span> <span class="Identifier">os</span><span class="Punctuation">]</span>
  120. <span class="Keyword">proc</span> <span class="Identifier">main</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">async</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
  121. <span class="Keyword">var</span> <span class="Identifier">file</span> <span class="Operator">=</span> <span class="Identifier">openAsync</span><span class="Punctuation">(</span><span class="Identifier">getTempDir</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">/</span> <span class="StringLit">&quot;foobar.txt&quot;</span><span class="Punctuation">,</span> <span class="Identifier">fmReadWrite</span><span class="Punctuation">)</span>
  122. <span class="Identifier">await</span> <span class="Identifier">file</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">&quot;test&quot;</span><span class="Punctuation">)</span>
  123. <span class="Identifier">file</span><span class="Operator">.</span><span class="Identifier">setFilePos</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  124. <span class="Keyword">let</span> <span class="Identifier">data</span> <span class="Operator">=</span> <span class="Identifier">await</span> <span class="Identifier">file</span><span class="Operator">.</span><span class="Identifier">readAll</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  125. <span class="Identifier">doAssert</span> <span class="Identifier">data</span> <span class="Operator">==</span> <span class="StringLit">&quot;test&quot;</span>
  126. <span class="Identifier">file</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  127. <span class="Identifier">waitFor</span> <span class="Identifier">main</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  128. </p>
  129. <div class="section" id="6">
  130. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  131. <dl class="item">
  132. <a class="reference external" href="asyncdispatch.html">asyncdispatch</a>, <a class="reference external" href="os.html">os</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="syncio.html">syncio</a>, <a class="reference external" href="widestrs.html">widestrs</a>, <a class="reference external" href="winlean.html">winlean</a>
  133. </dl>
  134. </div>
  135. <div class="section" id="7">
  136. <h1><a class="toc-backref" href="#7">Types</a></h1>
  137. <dl class="item">
  138. <div id="AsyncFile">
  139. <dt><pre><a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span></pre></dt>
  140. <dd>
  141. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L41" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  142. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L41" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  143. </dd>
  144. </div>
  145. </dl>
  146. </div>
  147. <div class="section" id="12">
  148. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  149. <dl class="item">
  150. <div id="close-procs-all">
  151. <div id="close,AsyncFile">
  152. <dt><pre><span class="Keyword">proc</span> <a href="#close%2CAsyncFile"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  153. <dd>
  154. Closes the file specified.
  155. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L505" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  156. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L505" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  157. </dd>
  158. </div>
  159. </div>
  160. <div id="getFilePos-procs-all">
  161. <div id="getFilePos,AsyncFile">
  162. <dt><pre><span class="Keyword">proc</span> <a href="#getFilePos%2CAsyncFile"><span class="Identifier">getFilePos</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int64"><span class="Identifier">int64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  163. <dd>
  164. Retrieves the current position of the file pointer that is used to read from the specified file. The file's first byte has the index zero.
  165. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L314" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  166. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L314" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  167. </dd>
  168. </div>
  169. </div>
  170. <div id="getFileSize-procs-all">
  171. <div id="getFileSize,AsyncFile">
  172. <dt><pre><span class="Keyword">proc</span> <a href="#getFileSize%2CAsyncFile"><span class="Identifier">getFileSize</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int64"><span class="Identifier">int64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  173. <dd>
  174. Retrieves the specified file's size.
  175. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L78" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  176. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L78" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  177. </dd>
  178. </div>
  179. </div>
  180. <div id="newAsyncFile-procs-all">
  181. <div id="newAsyncFile,AsyncFD">
  182. <dt><pre><span class="Keyword">proc</span> <a href="#newAsyncFile%2CAsyncFD"><span class="Identifier">newAsyncFile</span></a><span class="Other">(</span><span class="Identifier">fd</span><span class="Other">:</span> <a href="asyncdispatch.html#AsyncFD"><span class="Identifier">AsyncFD</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  183. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  184. <dd>
  185. Creates <tt class="docutils literal"><span class="pre"><span class="Identifier">AsyncFile</span></span></tt> with a previously opened file descriptor <tt class="docutils literal"><span class="pre"><span class="Identifier">fd</span></span></tt>.
  186. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L92" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  187. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L92" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  188. </dd>
  189. </div>
  190. </div>
  191. <div id="openAsync-procs-all">
  192. <div id="openAsync,string">
  193. <dt><pre><span class="Keyword">proc</span> <a href="#openAsync%2Cstring"><span class="Identifier">openAsync</span></a><span class="Other">(</span><span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">mode</span> <span class="Other">=</span> <span class="Identifier">fmRead</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  194. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  195. <dd>
  196. Opens a file specified by the path in <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> using the specified FileMode <tt class="docutils literal"><span class="pre"><span class="Identifier">mode</span></span></tt> asynchronously.
  197. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L98" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  198. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L98" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  199. </dd>
  200. </div>
  201. </div>
  202. <div id="read-procs-all">
  203. <div id="read,AsyncFile,int">
  204. <dt><pre><span class="Keyword">proc</span> <a href="#read%2CAsyncFile%2Cint"><span class="Identifier">read</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  205. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  206. <dd>
  207. <p>Read <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from the specified file asynchronously starting at the current position of the file pointer. <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> should be greater than zero.</p>
  208. <p>If the file pointer is past the end of the file then an empty string is returned.</p>
  209. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L204" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  210. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L204" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  211. </dd>
  212. </div>
  213. </div>
  214. <div id="readAll-procs-all">
  215. <div id="readAll,AsyncFile">
  216. <dt><pre><span class="Keyword">proc</span> <a href="#readAll%2CAsyncFile"><span class="Identifier">readAll</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
  217. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  218. <dd>
  219. Reads all data from the specified file.
  220. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L329" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  221. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L329" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  222. </dd>
  223. </div>
  224. </div>
  225. <div id="readBuffer-procs-all">
  226. <div id="readBuffer,AsyncFile,pointer,int">
  227. <dt><pre><span class="Keyword">proc</span> <a href="#readBuffer%2CAsyncFile%2Cpointer%2Cint"><span class="Identifier">readBuffer</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.
  228. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  229. <dd>
  230. <p>Read <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from the specified file asynchronously starting at the current position of the file pointer.</p>
  231. <p>If the file pointer is past the end of the file then zero is returned and no bytes are read into <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt></p>
  232. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L127" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  233. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L127" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  234. </dd>
  235. </div>
  236. </div>
  237. <div id="readLine-procs-all">
  238. <div id="readLine,AsyncFile">
  239. <dt><pre><span class="Keyword">proc</span> <a href="#readLine%2CAsyncFile"><span class="Identifier">readLine</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
  240. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  241. <dd>
  242. Reads a single line from the specified file asynchronously.
  243. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L299" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  244. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L299" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  245. </dd>
  246. </div>
  247. </div>
  248. <div id="readToStream-procs-all">
  249. <div id="readToStream,AsyncFile,FutureStream[string]">
  250. <dt><pre><span class="Keyword">proc</span> <a href="#readToStream%2CAsyncFile%2CFutureStream%5Bstring%5D"><span class="Identifier">readToStream</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">fs</span><span class="Other">:</span> <a href="asyncstreams.html#FutureStream"><span class="Identifier">FutureStream</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span>
  251. <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
  252. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  253. <dd>
  254. Writes data to the specified future stream as the file is read.
  255. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L529" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  256. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L529" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  257. </dd>
  258. </div>
  259. </div>
  260. <div id="setFilePos-procs-all">
  261. <div id="setFilePos,AsyncFile,int64">
  262. <dt><pre><span class="Keyword">proc</span> <a href="#setFilePos%2CAsyncFile%2Cint64"><span class="Identifier">setFilePos</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">pos</span><span class="Other">:</span> <a href="system.html#int64"><span class="Identifier">int64</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  263. <dd>
  264. Sets the position of the file pointer that is used for read/write operations. The file's first byte has the index zero.
  265. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L320" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  266. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L320" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  267. </dd>
  268. </div>
  269. </div>
  270. <div id="setFileSize-procs-all">
  271. <div id="setFileSize,AsyncFile,int64">
  272. <dt><pre><span class="Keyword">proc</span> <a href="#setFileSize%2CAsyncFile%2Cint64"><span class="Identifier">setFileSize</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">length</span><span class="Other">:</span> <a href="system.html#int64"><span class="Identifier">int64</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  273. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  274. <dd>
  275. Set a file length.
  276. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L488" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  277. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L488" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  278. </dd>
  279. </div>
  280. </div>
  281. <div id="write-procs-all">
  282. <div id="write,AsyncFile,string">
  283. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CAsyncFile%2Cstring"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
  284. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  285. <dd>
  286. <p>Writes <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> to the file specified asynchronously.</p>
  287. <p>The returned Future will complete once all data has been written to the specified file.</p>
  288. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L407" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  289. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L407" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  290. </dd>
  291. </div>
  292. </div>
  293. <div id="writeBuffer-procs-all">
  294. <div id="writeBuffer,AsyncFile,pointer,int">
  295. <dt><pre><span class="Keyword">proc</span> <a href="#writeBuffer%2CAsyncFile%2Cpointer%2Cint"><span class="Identifier">writeBuffer</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span> {.
  296. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  297. <dd>
  298. <p>Writes <tt class="docutils literal"><span class="pre"><span class="Identifier">size</span></span></tt> bytes from <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> to the file specified asynchronously.</p>
  299. <p>The returned Future will complete once all data has been written to the specified file.</p>
  300. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L338" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  301. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L338" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  302. </dd>
  303. </div>
  304. </div>
  305. <div id="writeFromStream-procs-all">
  306. <div id="writeFromStream,AsyncFile,FutureStream[string]">
  307. <dt><pre><span class="Keyword">proc</span> <a href="#writeFromStream%2CAsyncFile%2CFutureStream%5Bstring%5D"><span class="Identifier">writeFromStream</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="asyncfile.html#AsyncFile"><span class="Identifier">AsyncFile</span></a><span class="Other">;</span> <span class="Identifier">fs</span><span class="Other">:</span> <a href="asyncstreams.html#FutureStream"><span class="Identifier">FutureStream</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span>
  308. <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
  309. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  310. <dd>
  311. <p>Reads data from the specified future stream until it is completed. The data which is read is written to the file immediately and freed from memory.</p>
  312. <p>This procedure is perfect for saving streamed data to a file without wasting memory.</p>
  313. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asyncfile.nim#L515" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  314. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asyncfile.nim#L515" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  315. </dd>
  316. </div>
  317. </div>
  318. </dl>
  319. </div>
  320. </div>
  321. </div>
  322. <div class="twelve-columns footer">
  323. <span class="nim-sprite"></span>
  324. <br>
  325. <small style="color: var(--hint);">Made with Nim. Generated: 2025-01-09 12:00:14 UTC</small>
  326. </div>
  327. </div>
  328. </div>
  329. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  330. </body>
  331. </html>