syncio.html 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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/syncio</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/syncio</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="#File" title="File = ptr CFile">File</a></li>
  57. <li><a class="reference" href="#FileHandle" title="FileHandle = cint">FileHandle</a></li>
  58. <li><a class="reference" href="#FileMode" title="FileMode = enum
  59. fmRead, ## Open the file for read access only.
  60. ## If the file does not exist, it will not
  61. ## be created.
  62. fmWrite, ## Open the file for write access only.
  63. ## If the file does not exist, it will be
  64. ## created. Existing files will be cleared!
  65. fmReadWrite, ## Open the file for read and write access.
  66. ## If the file does not exist, it will be
  67. ## created. Existing files will be cleared!
  68. fmReadWriteExisting, ## Open the file for read and write access.
  69. ## If the file does not exist, it will not be
  70. ## created. The existing file will not be cleared.
  71. fmAppend ## Open the file for writing only; append data
  72. ## at the end. If the file does not exist, it
  73. ## will be created.">FileMode</a></li>
  74. <li><a class="reference" href="#FileSeekPos" title="FileSeekPos = enum
  75. fspSet, ## Seek to absolute value
  76. fspCur, ## Seek relative to current position
  77. fspEnd ## Seek relative to end">FileSeekPos</a></li>
  78. </ul>
  79. </details>
  80. </li>
  81. <li>
  82. <details open>
  83. <summary><a class="reference reference-toplevel" href="#8" id="58">Vars</a></summary>
  84. <ul class="simple simple-toc-section">
  85. <li><a class="reference" href="#stderr" title="stderr {.importc: &quot;stderr&quot;, header: &quot;&lt;stdio.h&gt;&quot;.}: File">stderr</a></li>
  86. <li><a class="reference" href="#stdin" title="stdin {.importc: &quot;stdin&quot;, header: &quot;&lt;stdio.h&gt;&quot;.}: File">stdin</a></li>
  87. <li><a class="reference" href="#stdout" title="stdout {.importc: &quot;stdout&quot;, header: &quot;&lt;stdio.h&gt;&quot;.}: File">stdout</a></li>
  88. </ul>
  89. </details>
  90. </li>
  91. <li>
  92. <details open>
  93. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  94. <ul class="simple simple-toc-section">
  95. <ul class="simple nested-toc-section">close
  96. <li><a class="reference" href="#close%2CFile" title="close(f: File)">close(f: File)</a></li>
  97. </ul>
  98. <ul class="simple nested-toc-section">endOfFile
  99. <li><a class="reference" href="#endOfFile%2CFile" title="endOfFile(f: File): bool">endOfFile(f: File): bool</a></li>
  100. </ul>
  101. <ul class="simple nested-toc-section">flushFile
  102. <li><a class="reference" href="#flushFile%2CFile" title="flushFile(f: File)">flushFile(f: File)</a></li>
  103. </ul>
  104. <ul class="simple nested-toc-section">getFileHandle
  105. <li><a class="reference" href="#getFileHandle%2CFile" title="getFileHandle(f: File): FileHandle">getFileHandle(f: File): FileHandle</a></li>
  106. </ul>
  107. <ul class="simple nested-toc-section">getFilePos
  108. <li><a class="reference" href="#getFilePos%2CFile" title="getFilePos(f: File): int64">getFilePos(f: File): int64</a></li>
  109. </ul>
  110. <ul class="simple nested-toc-section">getFileSize
  111. <li><a class="reference" href="#getFileSize%2CFile" title="getFileSize(f: File): int64">getFileSize(f: File): int64</a></li>
  112. </ul>
  113. <ul class="simple nested-toc-section">getOsFileHandle
  114. <li><a class="reference" href="#getOsFileHandle%2CFile" title="getOsFileHandle(f: File): FileHandle">getOsFileHandle(f: File): FileHandle</a></li>
  115. </ul>
  116. <ul class="simple nested-toc-section">open
  117. <li><a class="reference" href="#open%2CFile%2CFileHandle%2CFileMode" title="open(f: var File; filehandle: FileHandle; mode: FileMode = fmRead): bool">open(f: var File; filehandle: FileHandle; mode: FileMode = fmRead): bool</a></li>
  118. <li><a class="reference" href="#open%2CFile%2Cstring%2CFileMode%2Cint" title="open(f: var File; filename: string; mode: FileMode = fmRead; bufSize: int = -1): bool">open(f: var File; filename: string; mode: FileMode = fmRead; bufSize: int = -1): bool</a></li>
  119. <li><a class="reference" href="#open%2Cstring%2CFileMode%2Cint" title="open(filename: string; mode: FileMode = fmRead; bufSize: int = -1): File">open(filename: string; mode: FileMode = fmRead; bufSize: int = -1): File</a></li>
  120. </ul>
  121. <ul class="simple nested-toc-section">readAll
  122. <li><a class="reference" href="#readAll%2CFile" title="readAll(file: File): string">readAll(file: File): string</a></li>
  123. </ul>
  124. <ul class="simple nested-toc-section">readBuffer
  125. <li><a class="reference" href="#readBuffer%2CFile%2Cpointer%2CNatural" title="readBuffer(f: File; buffer: pointer; len: Natural): int">readBuffer(f: File; buffer: pointer; len: Natural): int</a></li>
  126. </ul>
  127. <ul class="simple nested-toc-section">readBytes
  128. <li><a class="reference" href="#readBytes%2CFile%2CopenArray%5B%5D%2CNatural%2CNatural" title="readBytes(f: File; a: var openArray[int8 | uint8]; start, len: Natural): int">readBytes(f: File; a: var openArray[int8 | uint8]; start, len: Natural): int</a></li>
  129. </ul>
  130. <ul class="simple nested-toc-section">readChar
  131. <li><a class="reference" href="#readChar%2CFile" title="readChar(f: File): char">readChar(f: File): char</a></li>
  132. </ul>
  133. <ul class="simple nested-toc-section">readChars
  134. <li><a class="reference" href="#readChars%2CFile%2CopenArray%5Bchar%5D" title="readChars(f: File; a: var openArray[char]): int">readChars(f: File; a: var openArray[char]): int</a></li>
  135. <li><a class="reference" href="#readChars%2CFile%2CopenArray%5Bchar%5D%2CNatural%2CNatural" title="readChars(f: File; a: var openArray[char]; start, len: Natural): int">readChars(f: File; a: var openArray[char]; start, len: Natural): int</a></li>
  136. </ul>
  137. <ul class="simple nested-toc-section">readFile
  138. <li><a class="reference" href="#readFile%2Cstring" title="readFile(filename: string): string">readFile(filename: string): string</a></li>
  139. </ul>
  140. <ul class="simple nested-toc-section">readLine
  141. <li><a class="reference" href="#readLine%2CFile" title="readLine(f: File): string">readLine(f: File): string</a></li>
  142. <li><a class="reference" href="#readLine%2CFile%2Cstring" title="readLine(f: File; line: var string): bool">readLine(f: File; line: var string): bool</a></li>
  143. </ul>
  144. <ul class="simple nested-toc-section">readLines
  145. <li><a class="reference" href="#readLines%2Cstring%2CNatural" title="readLines(filename: string; n: Natural): seq[string]">readLines(filename: string; n: Natural): seq[string]</a></li>
  146. </ul>
  147. <ul class="simple nested-toc-section">reopen
  148. <li><a class="reference" href="#reopen%2CFile%2Cstring%2CFileMode" title="reopen(f: File; filename: string; mode: FileMode = fmRead): bool">reopen(f: File; filename: string; mode: FileMode = fmRead): bool</a></li>
  149. </ul>
  150. <ul class="simple nested-toc-section">setFilePos
  151. <li><a class="reference" href="#setFilePos%2CFile%2Cint64%2CFileSeekPos" title="setFilePos(f: File; pos: int64; relativeTo: FileSeekPos = fspSet)">setFilePos(f: File; pos: int64; relativeTo: FileSeekPos = fspSet)</a></li>
  152. </ul>
  153. <ul class="simple nested-toc-section">setInheritable
  154. <li><a class="reference" href="#setInheritable%2CFileHandle%2Cbool" title="setInheritable(f: FileHandle; inheritable: bool): bool">setInheritable(f: FileHandle; inheritable: bool): bool</a></li>
  155. </ul>
  156. <ul class="simple nested-toc-section">setStdIoUnbuffered
  157. <li><a class="reference" href="#setStdIoUnbuffered" title="setStdIoUnbuffered()">setStdIoUnbuffered()</a></li>
  158. </ul>
  159. <ul class="simple nested-toc-section">write
  160. <li><a class="reference" href="#write%2CFile%2Cvarargs%5Bstring%2C%5D" title="write(f: File; a: varargs[string, `$`])">write(f: File; a: varargs[string, `$`])</a></li>
  161. <li><a class="reference" href="#write%2CFile%2Cbool" title="write(f: File; b: bool)">write(f: File; b: bool)</a></li>
  162. <li><a class="reference" href="#write%2CFile%2Cchar" title="write(f: File; c: char)">write(f: File; c: char)</a></li>
  163. <li><a class="reference" href="#write%2CFile%2Ccstring" title="write(f: File; c: cstring)">write(f: File; c: cstring)</a></li>
  164. <li><a class="reference" href="#write%2CFile%2CBiggestInt" title="write(f: File; i: BiggestInt)">write(f: File; i: BiggestInt)</a></li>
  165. <li><a class="reference" href="#write%2CFile%2Cint" title="write(f: File; i: int)">write(f: File; i: int)</a></li>
  166. <li><a class="reference" href="#write%2CFile%2CBiggestFloat" title="write(f: File; r: BiggestFloat)">write(f: File; r: BiggestFloat)</a></li>
  167. <li><a class="reference" href="#write%2CFile%2Cfloat32" title="write(f: File; r: float32)">write(f: File; r: float32)</a></li>
  168. <li><a class="reference" href="#write%2CFile%2Cstring" title="write(f: File; s: string)">write(f: File; s: string)</a></li>
  169. </ul>
  170. <ul class="simple nested-toc-section">writeBuffer
  171. <li><a class="reference" href="#writeBuffer%2CFile%2Cpointer%2CNatural" title="writeBuffer(f: File; buffer: pointer; len: Natural): int">writeBuffer(f: File; buffer: pointer; len: Natural): int</a></li>
  172. </ul>
  173. <ul class="simple nested-toc-section">writeBytes
  174. <li><a class="reference" href="#writeBytes%2CFile%2CopenArray%5B%5D%2CNatural%2CNatural" title="writeBytes(f: File; a: openArray[int8 | uint8]; start, len: Natural): int">writeBytes(f: File; a: openArray[int8 | uint8]; start, len: Natural): int</a></li>
  175. </ul>
  176. <ul class="simple nested-toc-section">writeChars
  177. <li><a class="reference" href="#writeChars%2CFile%2CopenArray%5Bchar%5D%2CNatural%2CNatural" title="writeChars(f: File; a: openArray[char]; start, len: Natural): int">writeChars(f: File; a: openArray[char]; start, len: Natural): int</a></li>
  178. </ul>
  179. <ul class="simple nested-toc-section">writeFile
  180. <li><a class="reference" href="#writeFile%2Cstring%2Cstring" title="writeFile(filename, content: string)">writeFile(filename, content: string)</a></li>
  181. <li><a class="reference" href="#writeFile%2Cstring%2CopenArray%5Bbyte%5D" title="writeFile(filename: string; content: openArray[byte])">writeFile(filename: string; content: openArray[byte])</a></li>
  182. </ul>
  183. <ul class="simple nested-toc-section">writeLine
  184. <li><a class="reference" href="#writeLine%2CFile%2Cvarargs%5BTy%2C%5D" title="writeLine[Ty](f: File; x: varargs[Ty, `$`])">writeLine[Ty](f: File; x: varargs[Ty, `$`])</a></li>
  185. </ul>
  186. </ul>
  187. </details>
  188. </li>
  189. <li>
  190. <details open>
  191. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  192. <ul class="simple simple-toc-section">
  193. <ul class="simple nested-toc-section">lines
  194. <li><a class="reference" href="#lines.i%2CFile" title="lines(f: File): string">lines(f: File): string</a></li>
  195. <li><a class="reference" href="#lines.i%2Cstring" title="lines(filename: string): string">lines(filename: string): string</a></li>
  196. </ul>
  197. </ul>
  198. </details>
  199. </li>
  200. <li>
  201. <details open>
  202. <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
  203. <ul class="simple simple-toc-section">
  204. <ul class="simple nested-toc-section">&=
  205. <li><a class="reference" href="#%26%3D.t%2CFile%2Ctyped" title="`&amp;=`(f: File; x: typed)">`&amp;=`(f: File; x: typed)</a></li>
  206. </ul>
  207. <ul class="simple nested-toc-section">readLines
  208. <li><a class="reference" href="#readLines.t%2Cstring" title="readLines(filename: string): seq[string]">readLines(filename: string): seq[string]</a></li>
  209. </ul>
  210. <ul class="simple nested-toc-section">stdmsg
  211. <li><a class="reference" href="#stdmsg.t" title="stdmsg(): File">stdmsg(): File</a></li>
  212. </ul>
  213. </ul>
  214. </details>
  215. </li>
  216. </ul>
  217. </div>
  218. <div class="nine columns" id="content">
  219. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  220. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  221. <div id="tocRoot"></div>
  222. <p class="module-desc">This module implements various synchronized I/O operations.</p>
  223. <div class="section" id="6">
  224. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  225. <dl class="item">
  226. <a class="reference external" href="since.html">since</a>, <a class="reference external" href="formatfloat.html">formatfloat</a>, <a class="reference external" href="ansi_c.html">ansi_c</a>
  227. </dl>
  228. </div>
  229. <div class="section" id="7">
  230. <h1><a class="toc-backref" href="#7">Types</a></h1>
  231. <dl class="item">
  232. <div id="File">
  233. <dt><pre><a href="syncio.html#File"><span class="Identifier">File</span></a> <span class="Other">=</span> <span class="Keyword">ptr</span> <span class="Identifier">CFile</span></pre></dt>
  234. <dd>
  235. The type representing a file handle.
  236. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L24" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  237. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L24" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  238. </dd>
  239. </div>
  240. <div id="FileHandle">
  241. <dt><pre><a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</span></a> <span class="Other">=</span> <a href="ctypes.html#cint"><span class="Identifier">cint</span></a></pre></dt>
  242. <dd>
  243. The type that represents an OS file handle; this is useful for low-level file access.
  244. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L43" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  245. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L43" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  246. </dd>
  247. </div>
  248. <div id="FileMode">
  249. <dt><pre><a href="syncio.html#FileMode"><span class="Identifier">FileMode</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  250. <span class="Identifier">fmRead</span><span class="Other">,</span> <span class="Comment">## Open the file for read access only.</span>
  251. <span class="Comment">## If the file does not exist, it will not</span>
  252. <span class="Comment">## be created.</span>
  253. <span class="Identifier">fmWrite</span><span class="Other">,</span> <span class="Comment">## Open the file for write access only.</span>
  254. <span class="Comment">## If the file does not exist, it will be</span>
  255. <span class="Comment">## created. Existing files will be cleared!</span>
  256. <span class="Identifier">fmReadWrite</span><span class="Other">,</span> <span class="Comment">## Open the file for read and write access.</span>
  257. <span class="Comment">## If the file does not exist, it will be</span>
  258. <span class="Comment">## created. Existing files will be cleared!</span>
  259. <span class="Identifier">fmReadWriteExisting</span><span class="Other">,</span> <span class="Comment">## Open the file for read and write access.</span>
  260. <span class="Comment">## If the file does not exist, it will not be</span>
  261. <span class="Comment">## created. The existing file will not be cleared.</span>
  262. <span class="Identifier">fmAppend</span> <span class="Comment">## Open the file for writing only; append data</span>
  263. <span class="Comment">## at the end. If the file does not exist, it</span>
  264. <span class="Comment">## will be created.</span></pre></dt>
  265. <dd>
  266. The file mode when opening a file.
  267. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L26" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  268. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L26" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  269. </dd>
  270. </div>
  271. <div id="FileSeekPos">
  272. <dt><pre><a href="syncio.html#FileSeekPos"><span class="Identifier">FileSeekPos</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  273. <span class="Identifier">fspSet</span><span class="Other">,</span> <span class="Comment">## Seek to absolute value</span>
  274. <span class="Identifier">fspCur</span><span class="Other">,</span> <span class="Comment">## Seek relative to current position</span>
  275. <span class="Identifier">fspEnd</span> <span class="Comment">## Seek relative to end</span></pre></dt>
  276. <dd>
  277. Position relative to which seek should happen.
  278. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L46" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  279. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L46" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  280. </dd>
  281. </div>
  282. </dl>
  283. </div>
  284. <div class="section" id="8">
  285. <h1><a class="toc-backref" href="#8">Vars</a></h1>
  286. <dl class="item">
  287. <div id="stderr">
  288. <dt><pre><a href="syncio.html#stderr"><span class="Identifier">stderr</span></a> {.<span class="Identifier">importc</span><span class="Other">:</span> <span class="StringLit">&quot;stderr&quot;</span><span class="Other">,</span> <span class="Identifier">header</span><span class="Other">:</span> <span class="StringLit">&quot;&lt;stdio.h&gt;&quot;</span>.}<span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a></pre></dt>
  289. <dd>
  290. The standard error stream.
  291. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L67" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  292. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L67" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  293. </dd>
  294. </div>
  295. <div id="stdin">
  296. <dt><pre><a href="syncio.html#stdin"><span class="Identifier">stdin</span></a> {.<span class="Identifier">importc</span><span class="Other">:</span> <span class="StringLit">&quot;stdin&quot;</span><span class="Other">,</span> <span class="Identifier">header</span><span class="Other">:</span> <span class="StringLit">&quot;&lt;stdio.h&gt;&quot;</span>.}<span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a></pre></dt>
  297. <dd>
  298. The standard input stream.
  299. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L63" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  300. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L63" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  301. </dd>
  302. </div>
  303. <div id="stdout">
  304. <dt><pre><a href="syncio.html#stdout"><span class="Identifier">stdout</span></a> {.<span class="Identifier">importc</span><span class="Other">:</span> <span class="StringLit">&quot;stdout&quot;</span><span class="Other">,</span> <span class="Identifier">header</span><span class="Other">:</span> <span class="StringLit">&quot;&lt;stdio.h&gt;&quot;</span>.}<span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a></pre></dt>
  305. <dd>
  306. The standard output stream.
  307. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L65" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  308. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L65" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  309. </dd>
  310. </div>
  311. </dl>
  312. </div>
  313. <div class="section" id="12">
  314. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  315. <dl class="item">
  316. <div id="close-procs-all">
  317. <div id="close,File">
  318. <dt><pre><span class="Keyword">proc</span> <a href="#close%2CFile"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> </span><span class="Identifier">sideEffect</span><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">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  319. <dd>
  320. Closes the file.
  321. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L341" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  322. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L341" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  323. </dd>
  324. </div>
  325. </div>
  326. <div id="endOfFile-procs-all">
  327. <div id="endOfFile,File">
  328. <dt><pre><span class="Keyword">proc</span> <a href="#endOfFile%2CFile"><span class="Identifier">endOfFile</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</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>
  329. <dd>
  330. Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt> is at the end.
  331. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L577" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  332. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L577" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  333. </dd>
  334. </div>
  335. </div>
  336. <div id="flushFile-procs-all">
  337. <div id="flushFile,File">
  338. <dt><pre><span class="Keyword">proc</span> <a href="#flushFile%2CFile"><span class="Identifier">flushFile</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</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>
  339. <dd>
  340. Flushes <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>'s buffer.
  341. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L354" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  342. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L354" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  343. </dd>
  344. </div>
  345. </div>
  346. <div id="getFileHandle-procs-all">
  347. <div id="getFileHandle,File">
  348. <dt><pre><span class="Keyword">proc</span> <a href="#getFileHandle%2CFile"><span class="Identifier">getFileHandle</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span><span class="Other">:</span> <a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</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>
  349. <dd>
  350. Returns the file handle of the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. This is only useful for platform specific programming. Note that on Windows this doesn't return the Windows-specific handle, but the C library's notion of a handle, whatever that means. Use <tt class="docutils literal"><span class="pre"><span class="Identifier">getOsFileHandle</span></span></tt> instead.
  351. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L358" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  352. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L358" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  353. </dd>
  354. </div>
  355. </div>
  356. <div id="getFilePos-procs-all">
  357. <div id="getFilePos,File">
  358. <dt><pre><span class="Keyword">proc</span> <a href="#getFilePos%2CFile"><span class="Identifier">getFilePos</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</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">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  359. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  360. <dd>
  361. Retrieves the current position of the file pointer that is used to read from the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. The file's first byte has the index zero.
  362. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L796" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  363. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L796" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  364. </dd>
  365. </div>
  366. </div>
  367. <div id="getFileSize-procs-all">
  368. <div id="getFileSize,File">
  369. <dt><pre><span class="Keyword">proc</span> <a href="#getFileSize%2CFile"><span class="Identifier">getFileSize</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</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">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  370. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  371. <dd>
  372. Retrieves the file size (in bytes) of <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>.
  373. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L802" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  374. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L802" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  375. </dd>
  376. </div>
  377. </div>
  378. <div id="getOsFileHandle-procs-all">
  379. <div id="getOsFileHandle,File">
  380. <dt><pre><span class="Keyword">proc</span> <a href="#getOsFileHandle%2CFile"><span class="Identifier">getOsFileHandle</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span><span class="Other">:</span> <a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</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>
  381. <dd>
  382. Returns the OS file handle of the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. This is only useful for platform specific programming.
  383. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L366" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  384. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L366" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  385. </dd>
  386. </div>
  387. </div>
  388. <div id="open-procs-all">
  389. <div id="open,File,FileHandle,FileMode">
  390. <dt><pre><span class="Keyword">proc</span> <a href="#open%2CFile%2CFileHandle%2CFileMode"><span class="Identifier">open</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">filehandle</span><span class="Other">:</span> <a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</span></a><span class="Other">;</span> <span class="Identifier">mode</span><span class="Other">:</span> <a href="syncio.html#FileMode"><span class="Identifier">FileMode</span></a> <span class="Other">=</span> <span class="Identifier">fmRead</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
  391. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</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>
  392. <dd>
  393. <p>Creates a <tt class="docutils literal"><span class="pre"><span class="Identifier">File</span></span></tt> from a <tt class="docutils literal"><span class="pre"><span class="Identifier">filehandle</span></span></tt> with given <tt class="docutils literal"><span class="pre"><span class="Identifier">mode</span></span></tt>.</p>
  394. <p>Default mode is readonly. Returns true if the file could be opened.</p>
  395. <p>The passed file handle will no longer be inheritable.</p>
  396. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L763" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  397. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L763" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  398. </dd>
  399. </div>
  400. <div id="open,File,string,FileMode,int">
  401. <dt><pre><span class="Keyword">proc</span> <a href="#open%2CFile%2Cstring%2CFileMode%2Cint"><span class="Identifier">open</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="syncio.html#File"><span class="Identifier">File</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> <a href="syncio.html#FileMode"><span class="Identifier">FileMode</span></a> <span class="Other">=</span> <span class="Identifier">fmRead</span><span class="Other">;</span>
  402. <span class="Identifier">bufSize</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</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>
  403. <dd>
  404. <p>Opens a file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> with given <tt class="docutils literal"><span class="pre"><span class="Identifier">mode</span></span></tt>.</p>
  405. <p>Default mode is readonly. Returns true if the file could be opened. This throws no exception if the file could not be opened.</p>
  406. <p>The file handle associated with the resulting <tt class="docutils literal"><span class="pre"><span class="Identifier">File</span></span></tt> is not inheritable.</p>
  407. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L709" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  408. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L709" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  409. </dd>
  410. </div>
  411. <div id="open,string,FileMode,int">
  412. <dt><pre><span class="Keyword">proc</span> <a href="#open%2Cstring%2CFileMode%2Cint"><span class="Identifier">open</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> <a href="syncio.html#FileMode"><span class="Identifier">FileMode</span></a> <span class="Other">=</span> <span class="Identifier">fmRead</span><span class="Other">;</span> <span class="Identifier">bufSize</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">)</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a> {.
  413. <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">IOError</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>
  414. <dd>
  415. <p>Opens a file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> with given <tt class="docutils literal"><span class="pre"><span class="Identifier">mode</span></span></tt>.</p>
  416. <p>Default mode is readonly. Raises an <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if the file could not be opened.</p>
  417. <p>The file handle associated with the resulting <tt class="docutils literal"><span class="pre"><span class="Identifier">File</span></span></tt> is not inheritable.</p>
  418. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L778" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  419. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L778" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  420. </dd>
  421. </div>
  422. </div>
  423. <div id="readAll-procs-all">
  424. <div id="readAll,File">
  425. <dt><pre><span class="Keyword">proc</span> <a href="#readAll%2CFile"><span class="Identifier">readAll</span></a><span class="Other">(</span><span class="Identifier">file</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  426. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  427. <dd>
  428. <p>Reads all data from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">file</span></span></tt>.</p>
  429. <p>Raises an IO exception in case of an error. It is an error if the current file position is not at the beginning of the file.</p>
  430. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L601" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  431. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L601" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  432. </dd>
  433. </div>
  434. </div>
  435. <div id="readBuffer-procs-all">
  436. <div id="readBuffer,File,pointer,Natural">
  437. <dt><pre><span class="Keyword">proc</span> <a href="#readBuffer%2CFile%2Cpointer%2CNatural"><span class="Identifier">readBuffer</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">buffer</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">len</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  438. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  439. <dd>
  440. Reads <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> bytes into the buffer pointed to by <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt>. Returns the actual number of bytes that have been read which may be less than <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> (if not as many bytes are remaining), but not greater.
  441. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L180" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  442. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L180" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  443. </dd>
  444. </div>
  445. </div>
  446. <div id="readBytes-procs-all">
  447. <div id="readBytes,File,openArray[],Natural,Natural">
  448. <dt><pre><span class="Keyword">proc</span> <a href="#readBytes%2CFile%2CopenArray%5B%5D%2CNatural%2CNatural"><span class="Identifier">readBytes</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">a</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#int8"><span class="Identifier">int8</span></a> <span class="Operator">|</span> <a href="system.html#uint8"><span class="Identifier">uint8</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span><span class="Other">,</span> <span class="Identifier">len</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  449. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span></span>.}</pre></dt>
  450. <dd>
  451. Reads <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> bytes into the buffer <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt> starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Punctuation">]</span></span></tt>. Returns the actual number of bytes that have been read which may be less than <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> (if not as many bytes are remaining), but not greater.
  452. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L188" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  453. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L188" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  454. </dd>
  455. </div>
  456. </div>
  457. <div id="readChar-procs-all">
  458. <div id="readChar,File">
  459. <dt><pre><span class="Keyword">proc</span> <a href="#readChar%2CFile"><span class="Identifier">readChar</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
  460. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">EOFError</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>
  461. <dd>
  462. Reads a single character from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. Should not be used in performance sensitive code.
  463. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L345" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  464. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L345" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  465. </dd>
  466. </div>
  467. </div>
  468. <div id="readChars-procs-all">
  469. <div id="readChars,File,openArray[char]">
  470. <dt><pre><span class="Keyword">proc</span> <a href="#readChars%2CFile%2CopenArray%5Bchar%5D"><span class="Identifier">readChars</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">a</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
  471. <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  472. <dd>
  473. Reads up to <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">len</span></span></tt> bytes into the buffer <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>. Returns the actual number of bytes that have been read which may be less than <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">len</span></span></tt> (if not as many bytes are remaining), but not greater.
  474. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L196" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  475. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L196" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  476. </dd>
  477. </div>
  478. <div id="readChars,File,openArray[char],Natural,Natural">
  479. <dt><pre><span class="Keyword">proc</span> <a href="#readChars%2CFile%2CopenArray%5Bchar%5D%2CNatural%2CNatural"><span class="Identifier">readChars</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">a</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span><span class="Other">,</span> <span class="Identifier">len</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  480. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;use other `readChars` overload, possibly via: readChars(toOpenArray(buf, start, len-1))&quot;</span><span class="Other">,</span>
  481. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  482. <dd>
  483. <div class="deprecation-message">
  484. <b>Deprecated:</b> use other `readChars` overload, possibly via: readChars(toOpenArray(buf, start, len-1))
  485. </div>
  486. Reads <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> bytes into the buffer <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt> starting at <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Punctuation">]</span></span></tt>. Returns the actual number of bytes that have been read which may be less than <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> (if not as many bytes are remaining), but not greater.
  487. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L202" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  488. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L202" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  489. </dd>
  490. </div>
  491. </div>
  492. <div id="readFile-procs-all">
  493. <div id="readFile,string">
  494. <dt><pre><span class="Keyword">proc</span> <a href="#readFile%2Cstring"><span class="Identifier">readFile</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="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  495. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  496. <dd>
  497. Opens a file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> for reading, calls <a class="reference external" href="#readAll,File">readAll</a> and closes the file afterwards. Returns the string. Raises an IO exception in case of an error. If you need to call this inside a compile time macro you can use <a class="reference external" href="system.html#staticRead,string">staticRead</a>.
  498. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L863" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  499. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L863" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  500. </dd>
  501. </div>
  502. </div>
  503. <div id="readLine-procs-all">
  504. <div id="readLine,File">
  505. <dt><pre><span class="Keyword">proc</span> <a href="#readLine%2CFile"><span class="Identifier">readLine</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  506. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">EOFError</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>
  507. <dd>
  508. Reads a line of text from the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. May throw an IO exception. A line of text may be delimited by <tt class="docutils literal"><span class="pre"><span class="Identifier">LF</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">CRLF</span></span></tt>. The newline character(s) are not part of the returned string.
  509. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L517" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  510. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L517" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  511. </dd>
  512. </div>
  513. <div id="readLine,File,string">
  514. <dt><pre><span class="Keyword">proc</span> <a href="#readLine%2CFile%2Cstring"><span class="Identifier">readLine</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">line</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  515. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  516. <dd>
  517. Reads a line of text from the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt> into <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt>. May throw an IO exception. A line of text may be delimited by <tt class="docutils literal"><span class="pre"><span class="Identifier">LF</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">CRLF</span></span></tt>. The newline character(s) are not part of the returned string. Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> if the end of the file has been reached, <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> otherwise. If <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> is returned <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> contains no new data.
  518. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L396" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  519. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L396" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  520. </dd>
  521. </div>
  522. </div>
  523. <div id="readLines-procs-all">
  524. <div id="readLines,string,Natural">
  525. <dt><pre><span class="Keyword">proc</span> <a href="#readLines%2Cstring%2CNatural"><span class="Identifier">readLines</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">n</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  526. <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">IOError</span><span class="Other">,</span> <span class="Identifier">EOFError</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">ReadIOEffect</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>
  527. <dd>
  528. Reads <tt class="docutils literal"><span class="pre"><span class="Identifier">n</span></span></tt> lines from the file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt>. Raises an IO exception in case of an error. Raises EOF if file does not contain at least <tt class="docutils literal"><span class="pre"><span class="Identifier">n</span></span></tt> lines. Available at compile time. A line of text may be delimited by <tt class="docutils literal"><span class="pre"><span class="Identifier">LF</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">CRLF</span></span></tt>. The newline character(s) are not part of the returned strings.
  529. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L904" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  530. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L904" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  531. </dd>
  532. </div>
  533. </div>
  534. <div id="reopen-procs-all">
  535. <div id="reopen,File,string,FileMode">
  536. <dt><pre><span class="Keyword">proc</span> <a href="#reopen%2CFile%2Cstring%2CFileMode"><span class="Identifier">reopen</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</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> <a href="syncio.html#FileMode"><span class="Identifier">FileMode</span></a> <span class="Other">=</span> <span class="Identifier">fmRead</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
  537. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</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>
  538. <dd>
  539. <p>Reopens the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt> with given <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">mode</span></span></tt>. This is often used to redirect the <tt class="docutils literal"><span class="pre"><span class="Identifier">stdin</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">stdout</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">stderr</span></span></tt> file variables.</p>
  540. <p>Default mode is readonly. Returns true if the file could be reopened.</p>
  541. <p>The file handle associated with <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt> won't be inheritable.</p>
  542. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L744" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  543. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L744" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  544. </dd>
  545. </div>
  546. </div>
  547. <div id="setFilePos-procs-all">
  548. <div id="setFilePos,File,int64,FileSeekPos">
  549. <dt><pre><span class="Keyword">proc</span> <a href="#setFilePos%2CFile%2Cint64%2CFileSeekPos"><span class="Identifier">setFilePos</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</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 class="Identifier">relativeTo</span><span class="Other">:</span> <a href="syncio.html#FileSeekPos"><span class="Identifier">FileSeekPos</span></a> <span class="Other">=</span> <span class="Identifier">fspSet</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
  550. </span><span class="Identifier">sideEffect</span><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">IOError</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>
  551. <dd>
  552. Sets the position of the file pointer that is used for read/write operations. The file's first byte has the index zero.
  553. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L790" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  554. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L790" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  555. </dd>
  556. </div>
  557. </div>
  558. <div id="setInheritable-procs-all">
  559. <div id="setInheritable,FileHandle,bool">
  560. <dt><pre><span class="Keyword">proc</span> <a href="#setInheritable%2CFileHandle%2Cbool"><span class="Identifier">setInheritable</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#FileHandle"><span class="Identifier">FileHandle</span></a><span class="Other">;</span> <span class="Identifier">inheritable</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</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>
  561. <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>
  562. <dd>
  563. <p>Controls whether a file handle can be inherited by child processes. Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> on success. This requires the OS file handle, which can be retrieved via <a class="reference external" href="#getOsFileHandle,File">getOsFileHandle</a>.</p>
  564. <p>This procedure is not guaranteed to be available for all platforms. Test for availability with <a class="reference external" href="system.html#declared,untyped">declared()</a>.</p>
  565. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L375" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  566. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L375" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  567. </dd>
  568. </div>
  569. </div>
  570. <div id="setStdIoUnbuffered-procs-all">
  571. <div id="setStdIoUnbuffered">
  572. <dt><pre><span class="Keyword">proc</span> <a href="#setStdIoUnbuffered"><span class="Identifier">setStdIoUnbuffered</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</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>
  573. <dd>
  574. Configures <tt class="docutils literal"><span class="pre"><span class="Identifier">stdin</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">stdout</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">stderr</span></span></tt> to be unbuffered.
  575. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L809" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  576. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L809" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  577. </dd>
  578. </div>
  579. </div>
  580. <div id="write-procs-all">
  581. <div id="write,File,varargs[string,]">
  582. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">a</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</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="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  583. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  584. <dd>
  585. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L553" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  586. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L553" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  587. </dd>
  588. </div>
  589. <div id="write,File,bool">
  590. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2Cbool"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">b</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
  591. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  592. <dd>
  593. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L536" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  594. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L536" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  595. </dd>
  596. </div>
  597. <div id="write,File,char">
  598. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2Cchar"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">c</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  599. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  600. <dd>
  601. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L550" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  602. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L550" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  603. </dd>
  604. </div>
  605. <div id="write,File,cstring">
  606. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2Ccstring"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">c</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  607. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  608. <dd>
  609. Writes a value to the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. May throw an IO exception.
  610. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L212" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  611. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L212" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  612. </dd>
  613. </div>
  614. <div id="write,File,BiggestInt">
  615. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2CBiggestInt"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="ctypes.html#BiggestInt"><span class="Identifier">BiggestInt</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  616. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  617. <dd>
  618. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L530" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  619. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L530" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  620. </dd>
  621. </div>
  622. <div id="write,File,int">
  623. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2Cint"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
  624. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  625. <dd>
  626. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L524" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  627. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L524" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  628. </dd>
  629. </div>
  630. <div id="write,File,BiggestFloat">
  631. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2CBiggestFloat"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">r</span><span class="Other">:</span> <a href="ctypes.html#BiggestFloat"><span class="Identifier">BiggestFloat</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  632. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  633. <dd>
  634. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L545" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  635. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L545" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  636. </dd>
  637. </div>
  638. <div id="write,File,float32">
  639. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2Cfloat32"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">r</span><span class="Other">:</span> <a href="system.html#float32"><span class="Identifier">float32</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  640. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  641. <dd>
  642. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L540" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  643. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L540" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  644. </dd>
  645. </div>
  646. <div id="write,File,string">
  647. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CFile%2Cstring"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">s</span><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">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  648. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  649. <dd>
  650. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L263" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  651. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L263" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  652. </dd>
  653. </div>
  654. </div>
  655. <div id="writeBuffer-procs-all">
  656. <div id="writeBuffer,File,pointer,Natural">
  657. <dt><pre><span class="Keyword">proc</span> <a href="#writeBuffer%2CFile%2Cpointer%2CNatural"><span class="Identifier">writeBuffer</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">buffer</span><span class="Other">:</span> <a href="system.html#pointer"><span class="Identifier">pointer</span></a><span class="Other">;</span> <span class="Identifier">len</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  658. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  659. <dd>
  660. Writes the bytes of buffer pointed to by the parameter <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt> to the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. Returns the number of actual written bytes, which may be less than <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> in case of an error.
  661. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L217" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  662. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L217" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  663. </dd>
  664. </div>
  665. </div>
  666. <div id="writeBytes-procs-all">
  667. <div id="writeBytes,File,openArray[],Natural,Natural">
  668. <dt><pre><span class="Keyword">proc</span> <a href="#writeBytes%2CFile%2CopenArray%5B%5D%2CNatural%2CNatural"><span class="Identifier">writeBytes</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">a</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#int8"><span class="Identifier">int8</span></a> <span class="Operator">|</span> <a href="system.html#uint8"><span class="Identifier">uint8</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span><span class="Other">,</span> <span class="Identifier">len</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  669. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span></span>.}</pre></dt>
  670. <dd>
  671. Writes the bytes of <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Operator">..</span><span class="Identifier">start</span><span class="Operator">+</span><span class="Identifier">len</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span></span></tt> to the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. Returns the number of actual written bytes, which may be less than <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> in case of an error.
  672. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L225" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  673. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L225" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  674. </dd>
  675. </div>
  676. </div>
  677. <div id="writeChars-procs-all">
  678. <div id="writeChars,File,openArray[char],Natural,Natural">
  679. <dt><pre><span class="Keyword">proc</span> <a href="#writeChars%2CFile%2CopenArray%5Bchar%5D%2CNatural%2CNatural"><span class="Identifier">writeChars</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">a</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">start</span><span class="Other">,</span> <span class="Identifier">len</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  680. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  681. <dd>
  682. Writes the bytes of <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Operator">..</span><span class="Identifier">start</span><span class="Operator">+</span><span class="Identifier">len</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span></span></tt> to the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>. Returns the number of actual written bytes, which may be less than <tt class="docutils literal"><span class="pre"><span class="Identifier">len</span></span></tt> in case of an error.
  683. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L233" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  684. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L233" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  685. </dd>
  686. </div>
  687. </div>
  688. <div id="writeFile-procs-all">
  689. <div id="writeFile,string,string">
  690. <dt><pre><span class="Keyword">proc</span> <a href="#writeFile%2Cstring%2Cstring"><span class="Identifier">writeFile</span></a><span class="Other">(</span><span class="Identifier">filename</span><span class="Other">,</span> <span class="Identifier">content</span><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">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span><span class="Other">,</span>
  691. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</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>
  692. <dd>
  693. Opens a file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> for writing. Then writes the <tt class="docutils literal"><span class="pre"><span class="Identifier">content</span></span></tt> completely to the file and closes the file afterwards. Raises an IO exception in case of an error.
  694. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L878" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  695. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L878" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  696. </dd>
  697. </div>
  698. <div id="writeFile,string,openArray[byte]">
  699. <dt><pre><span class="Keyword">proc</span> <a href="#writeFile%2Cstring%2CopenArray%5Bbyte%5D"><span class="Identifier">writeFile</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">content</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="system.html#byte"><span class="Identifier">byte</span></a><span class="Other">]</span><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">IOError</span><span class="Other">]</span><span class="Other">,</span>
  700. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</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>
  701. <dd>
  702. Opens a file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> for writing. Then writes the <tt class="docutils literal"><span class="pre"><span class="Identifier">content</span></span></tt> completely to the file and closes the file afterwards. Raises an IO exception in case of an error.
  703. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L891" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  704. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L891" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  705. </dd>
  706. </div>
  707. </div>
  708. <div id="writeLine-procs-all">
  709. <div id="writeLine,File,varargs[Ty,]">
  710. <dt><pre><span class="Keyword">proc</span> <a href="#writeLine%2CFile%2Cvarargs%5BTy%2C%5D"><span class="Identifier">writeLine</span></a><span class="Other">[</span><span class="Identifier">Ty</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><span class="Identifier">Ty</span><span class="Other">,</span> <span class="Other">`</span><span class="Operator">$</span><span class="Other">`</span><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span><span class="Other">,</span>
  711. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">gcsafe</span></span>.}</pre></dt>
  712. <dd>
  713. Writes the values <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt> and then writes &quot;\n&quot;. May throw an IO exception.
  714. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L618" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  715. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L618" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  716. </dd>
  717. </div>
  718. </div>
  719. </dl>
  720. </div>
  721. <div class="section" id="15">
  722. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  723. <dl class="item">
  724. <div id="lines-iterators-all">
  725. <div id="lines.i,File">
  726. <dt><pre><span class="Keyword">iterator</span> <a href="#lines.i%2CFile"><span class="Identifier">lines</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
  727. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  728. <dd>
  729. <p>Iterates over any line in the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>.</p>
  730. <p>The trailing newline character(s) are removed from the iterated lines. </p>
  731. <p><strong class="examples_text">Example:</strong></p>
  732. <pre class="listing"><span class="Keyword">proc</span> <span class="Identifier">countZeros</span><span class="Punctuation">(</span><span class="Identifier">filename</span><span class="Punctuation">:</span> <span class="Identifier">File</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">tuple</span><span class="Punctuation">[</span><span class="Identifier">lines</span><span class="Punctuation">,</span> <span class="Identifier">zeros</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">]</span> <span class="Operator">=</span>
  733. <span class="Keyword">for</span> <span class="Identifier">line</span> <span class="Keyword">in</span> <span class="Identifier">filename</span><span class="Operator">.</span><span class="Identifier">lines</span><span class="Punctuation">:</span>
  734. <span class="Keyword">for</span> <span class="Identifier">letter</span> <span class="Keyword">in</span> <span class="Identifier">line</span><span class="Punctuation">:</span>
  735. <span class="Keyword">if</span> <span class="Identifier">letter</span> <span class="Operator">==</span> <span class="CharLit">'0'</span><span class="Punctuation">:</span>
  736. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">zeros</span> <span class="Operator">+=</span> <span class="DecNumber">1</span>
  737. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">lines</span> <span class="Operator">+=</span> <span class="DecNumber">1</span></pre>
  738. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L946" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  739. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L946" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  740. </dd>
  741. </div>
  742. <div id="lines.i,string">
  743. <dt><pre><span class="Keyword">iterator</span> <a href="#lines.i%2Cstring"><span class="Identifier">lines</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="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">]</span><span class="Other">,</span>
  744. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">IOError</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>
  745. <dd>
  746. <p>Iterates over any line in the file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt>.</p>
  747. <p>If the file does not exist <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> is raised. The trailing newline character(s) are removed from the iterated lines. Example: </p>
  748. <p><strong class="examples_text">Example:</strong></p>
  749. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strutils</span>
  750. <span class="Keyword">proc</span> <span class="Identifier">transformLetters</span><span class="Punctuation">(</span><span class="Identifier">filename</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">)</span> <span class="Operator">=</span>
  751. <span class="Keyword">var</span> <span class="Identifier">buffer</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  752. <span class="Keyword">for</span> <span class="Identifier">line</span> <span class="Keyword">in</span> <span class="Identifier">filename</span><span class="Operator">.</span><span class="Identifier">lines</span><span class="Punctuation">:</span>
  753. <span class="Identifier">buffer</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Operator">.</span><span class="Identifier">replace</span><span class="Punctuation">(</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;0&quot;</span><span class="Punctuation">)</span> <span class="Operator">&amp;</span> <span class="CharLit">'\n'</span><span class="Punctuation">)</span>
  754. <span class="Identifier">writeFile</span><span class="Punctuation">(</span><span class="Identifier">filename</span><span class="Punctuation">,</span> <span class="Identifier">buffer</span><span class="Punctuation">)</span></pre>
  755. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L925" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  756. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L925" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  757. </dd>
  758. </div>
  759. </div>
  760. </dl>
  761. </div>
  762. <div class="section" id="18">
  763. <h1><a class="toc-backref" href="#18">Templates</a></h1>
  764. <dl class="item">
  765. <div id="&amp;=-templates-all">
  766. <div id="&=.t,File,typed">
  767. <dt><pre><span class="Keyword">template</span> <a href="#%26%3D.t%2CFile%2Ctyped"><span class="Identifier">`&amp;=`</span></a><span class="Other">(</span><span class="Identifier">f</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a><span class="Other">;</span> <span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">)</span></pre></dt>
  768. <dd>
  769. An alias for <tt class="docutils literal"><span class="pre"><span class="Identifier">write</span></span></tt>.
  770. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L961" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  771. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L961" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  772. </dd>
  773. </div>
  774. </div>
  775. <div id="readLines-templates-all">
  776. <div id="readLines.t,string">
  777. <dt><pre><span class="Keyword">template</span> <a href="#readLines.t%2Cstring"><span class="Identifier">readLines</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="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  778. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;use readLines with two arguments&quot;</span></span>.}</pre></dt>
  779. <dd>
  780. <div class="deprecation-message">
  781. <b>Deprecated:</b> use readLines with two arguments
  782. </div>
  783. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L921" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  784. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L921" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  785. </dd>
  786. </div>
  787. </div>
  788. <div id="stdmsg-templates-all">
  789. <div id="stdmsg.t">
  790. <dt><pre><span class="Keyword">template</span> <a href="#stdmsg.t"><span class="Identifier">stdmsg</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="syncio.html#File"><span class="Identifier">File</span></a></pre></dt>
  791. <dd>
  792. Template which expands to either stdout or stderr depending on <tt class="docutils literal"><span class="pre"><span class="Identifier">useStdoutAsStdmsg</span></span></tt> compile-time switch.
  793. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/syncio.nim#L73" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  794. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/syncio.nim#L73" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  795. </dd>
  796. </div>
  797. </div>
  798. </dl>
  799. </div>
  800. </div>
  801. </div>
  802. <div class="twelve-columns footer">
  803. <span class="nim-sprite"></span>
  804. <br>
  805. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:28:23 UTC</small>
  806. </div>
  807. </div>
  808. </div>
  809. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  810. </body>
  811. </html>