streams.html 259 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  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/streams</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/streams</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><a class="reference" id="basic-usage_toc" href="#basic-usage">Basic usage</a></li>
  50. <ul class="simple"><li><a class="reference" id="basic-usage-stringstream-example_toc" href="#basic-usage-stringstream-example">StringStream example</a></li>
  51. <li><a class="reference" id="basic-usage-filestream-example_toc" href="#basic-usage-filestream-example">FileStream example</a></li>
  52. </ul><li><a class="reference" id="see-also_toc" href="#see-also">See also</a></li>
  53. <li>
  54. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  55. </li>
  56. <li>
  57. <details open>
  58. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  59. <ul class="simple simple-toc-section">
  60. <li><a class="reference" href="#FileStream" title="FileStream = ref FileStreamObj">FileStream</a></li>
  61. <li><a class="reference" href="#FileStreamObj" title="FileStreamObj = object of Stream">FileStreamObj</a></li>
  62. <li><a class="reference" href="#Stream" title="Stream = ref StreamObj">Stream</a></li>
  63. <li><a class="reference" href="#StreamObj" title="StreamObj = object of RootObj
  64. closeImpl*: proc (s: Stream) {.nimcall, raises: [IOError, OSError],
  65. tags: [WriteIOEffect], gcsafe.}
  66. atEndImpl*: proc (s: Stream): bool {.nimcall,
  67. raises: [Defect, IOError, OSError],
  68. tags: [], gcsafe.}
  69. setPositionImpl*: proc (s: Stream; pos: int) {.nimcall,
  70. raises: [Defect, IOError, OSError], tags: [], gcsafe.}
  71. getPositionImpl*: proc (s: Stream): int {.nimcall,
  72. raises: [Defect, IOError, OSError], tags: [], gcsafe.}
  73. readDataStrImpl*: proc (s: Stream; buffer: var string; slice: Slice[int]): int {.
  74. nimcall, raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
  75. readLineImpl*: proc (s: Stream; line: var string): bool {.nimcall,
  76. raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
  77. readDataImpl*: proc (s: Stream; buffer: pointer; bufLen: int): int {.nimcall,
  78. raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
  79. peekDataImpl*: proc (s: Stream; buffer: pointer; bufLen: int): int {.nimcall,
  80. raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
  81. writeDataImpl*: proc (s: Stream; buffer: pointer; bufLen: int) {.nimcall,
  82. raises: [Defect, IOError, OSError], tags: [WriteIOEffect], gcsafe.}
  83. flushImpl*: proc (s: Stream) {.nimcall, raises: [Defect, IOError, OSError],
  84. tags: [WriteIOEffect], gcsafe.}">StreamObj</a></li>
  85. <li><a class="reference" href="#StringStream" title="StringStream = ref StringStreamObj">StringStream</a></li>
  86. <li><a class="reference" href="#StringStreamObj" title="StringStreamObj = object of StreamObj
  87. data*: string ## A string data.
  88. ## This is updated when called `writeLine` etc.">StringStreamObj</a></li>
  89. </ul>
  90. </details>
  91. </li>
  92. <li>
  93. <details open>
  94. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  95. <ul class="simple simple-toc-section">
  96. <ul class="simple nested-toc-section">atEnd
  97. <li><a class="reference" href="#atEnd%2CStream" title="atEnd(s: Stream): bool">atEnd(s: Stream): bool</a></li>
  98. </ul>
  99. <ul class="simple nested-toc-section">close
  100. <li><a class="reference" href="#close%2CStream" title="close(s: Stream)">close(s: Stream)</a></li>
  101. </ul>
  102. <ul class="simple nested-toc-section">flush
  103. <li><a class="reference" href="#flush%2CStream" title="flush(s: Stream)">flush(s: Stream)</a></li>
  104. </ul>
  105. <ul class="simple nested-toc-section">getPosition
  106. <li><a class="reference" href="#getPosition%2CStream" title="getPosition(s: Stream): int">getPosition(s: Stream): int</a></li>
  107. </ul>
  108. <ul class="simple nested-toc-section">newFileStream
  109. <li><a class="reference" href="#newFileStream%2CFile" title="newFileStream(f: File): owned FileStream">newFileStream(f: File): owned FileStream</a></li>
  110. <li><a class="reference" href="#newFileStream%2Cstring%2CFileMode%2Cint" title="newFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
  111. FileStream">newFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
  112. FileStream</a></li>
  113. </ul>
  114. <ul class="simple nested-toc-section">newStringStream
  115. <li><a class="reference" href="#newStringStream%2Csinkstring" title="newStringStream(s: sink string = &quot;&quot;): owned StringStream">newStringStream(s: sink string = &quot;&quot;): owned StringStream</a></li>
  116. </ul>
  117. <ul class="simple nested-toc-section">openFileStream
  118. <li><a class="reference" href="#openFileStream%2Cstring%2CFileMode%2Cint" title="openFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
  119. FileStream">openFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
  120. FileStream</a></li>
  121. </ul>
  122. <ul class="simple nested-toc-section">peek
  123. <li><a class="reference" href="#peek%2CStream%2CT" title="peek[T](s: Stream; result: var T)">peek[T](s: Stream; result: var T)</a></li>
  124. </ul>
  125. <ul class="simple nested-toc-section">peekBool
  126. <li><a class="reference" href="#peekBool%2CStream" title="peekBool(s: Stream): bool">peekBool(s: Stream): bool</a></li>
  127. </ul>
  128. <ul class="simple nested-toc-section">peekChar
  129. <li><a class="reference" href="#peekChar%2CStream" title="peekChar(s: Stream): char">peekChar(s: Stream): char</a></li>
  130. </ul>
  131. <ul class="simple nested-toc-section">peekData
  132. <li><a class="reference" href="#peekData%2CStream%2Cpointer%2Cint" title="peekData(s: Stream; buffer: pointer; bufLen: int): int">peekData(s: Stream; buffer: pointer; bufLen: int): int</a></li>
  133. </ul>
  134. <ul class="simple nested-toc-section">peekFloat32
  135. <li><a class="reference" href="#peekFloat32%2CStream" title="peekFloat32(s: Stream): float32">peekFloat32(s: Stream): float32</a></li>
  136. </ul>
  137. <ul class="simple nested-toc-section">peekFloat64
  138. <li><a class="reference" href="#peekFloat64%2CStream" title="peekFloat64(s: Stream): float64">peekFloat64(s: Stream): float64</a></li>
  139. </ul>
  140. <ul class="simple nested-toc-section">peekInt8
  141. <li><a class="reference" href="#peekInt8%2CStream" title="peekInt8(s: Stream): int8">peekInt8(s: Stream): int8</a></li>
  142. </ul>
  143. <ul class="simple nested-toc-section">peekInt16
  144. <li><a class="reference" href="#peekInt16%2CStream" title="peekInt16(s: Stream): int16">peekInt16(s: Stream): int16</a></li>
  145. </ul>
  146. <ul class="simple nested-toc-section">peekInt32
  147. <li><a class="reference" href="#peekInt32%2CStream" title="peekInt32(s: Stream): int32">peekInt32(s: Stream): int32</a></li>
  148. </ul>
  149. <ul class="simple nested-toc-section">peekInt64
  150. <li><a class="reference" href="#peekInt64%2CStream" title="peekInt64(s: Stream): int64">peekInt64(s: Stream): int64</a></li>
  151. </ul>
  152. <ul class="simple nested-toc-section">peekLine
  153. <li><a class="reference" href="#peekLine%2CStream" title="peekLine(s: Stream): string">peekLine(s: Stream): string</a></li>
  154. <li><a class="reference" href="#peekLine%2CStream%2Cstring" title="peekLine(s: Stream; line: var string): bool">peekLine(s: Stream; line: var string): bool</a></li>
  155. </ul>
  156. <ul class="simple nested-toc-section">peekStr
  157. <li><a class="reference" href="#peekStr%2CStream%2Cint" title="peekStr(s: Stream; length: int): string">peekStr(s: Stream; length: int): string</a></li>
  158. <li><a class="reference" href="#peekStr%2CStream%2Cint%2Cstring" title="peekStr(s: Stream; length: int; str: var string)">peekStr(s: Stream; length: int; str: var string)</a></li>
  159. </ul>
  160. <ul class="simple nested-toc-section">peekUint8
  161. <li><a class="reference" href="#peekUint8%2CStream" title="peekUint8(s: Stream): uint8">peekUint8(s: Stream): uint8</a></li>
  162. </ul>
  163. <ul class="simple nested-toc-section">peekUint16
  164. <li><a class="reference" href="#peekUint16%2CStream" title="peekUint16(s: Stream): uint16">peekUint16(s: Stream): uint16</a></li>
  165. </ul>
  166. <ul class="simple nested-toc-section">peekUint32
  167. <li><a class="reference" href="#peekUint32%2CStream" title="peekUint32(s: Stream): uint32">peekUint32(s: Stream): uint32</a></li>
  168. </ul>
  169. <ul class="simple nested-toc-section">peekUint64
  170. <li><a class="reference" href="#peekUint64%2CStream" title="peekUint64(s: Stream): uint64">peekUint64(s: Stream): uint64</a></li>
  171. </ul>
  172. <ul class="simple nested-toc-section">read
  173. <li><a class="reference" href="#read%2CStream%2CT" title="read[T](s: Stream; result: var T)">read[T](s: Stream; result: var T)</a></li>
  174. </ul>
  175. <ul class="simple nested-toc-section">readAll
  176. <li><a class="reference" href="#readAll%2CStream" title="readAll(s: Stream): string">readAll(s: Stream): string</a></li>
  177. </ul>
  178. <ul class="simple nested-toc-section">readBool
  179. <li><a class="reference" href="#readBool%2CStream" title="readBool(s: Stream): bool">readBool(s: Stream): bool</a></li>
  180. </ul>
  181. <ul class="simple nested-toc-section">readChar
  182. <li><a class="reference" href="#readChar%2CStream" title="readChar(s: Stream): char">readChar(s: Stream): char</a></li>
  183. </ul>
  184. <ul class="simple nested-toc-section">readData
  185. <li><a class="reference" href="#readData%2CStream%2Cpointer%2Cint" title="readData(s: Stream; buffer: pointer; bufLen: int): int">readData(s: Stream; buffer: pointer; bufLen: int): int</a></li>
  186. </ul>
  187. <ul class="simple nested-toc-section">readDataStr
  188. <li><a class="reference" href="#readDataStr%2CStream%2Cstring%2CSlice%5Bint%5D" title="readDataStr(s: Stream; buffer: var string; slice: Slice[int]): int">readDataStr(s: Stream; buffer: var string; slice: Slice[int]): int</a></li>
  189. </ul>
  190. <ul class="simple nested-toc-section">readFloat32
  191. <li><a class="reference" href="#readFloat32%2CStream" title="readFloat32(s: Stream): float32">readFloat32(s: Stream): float32</a></li>
  192. </ul>
  193. <ul class="simple nested-toc-section">readFloat64
  194. <li><a class="reference" href="#readFloat64%2CStream" title="readFloat64(s: Stream): float64">readFloat64(s: Stream): float64</a></li>
  195. </ul>
  196. <ul class="simple nested-toc-section">readInt8
  197. <li><a class="reference" href="#readInt8%2CStream" title="readInt8(s: Stream): int8">readInt8(s: Stream): int8</a></li>
  198. </ul>
  199. <ul class="simple nested-toc-section">readInt16
  200. <li><a class="reference" href="#readInt16%2CStream" title="readInt16(s: Stream): int16">readInt16(s: Stream): int16</a></li>
  201. </ul>
  202. <ul class="simple nested-toc-section">readInt32
  203. <li><a class="reference" href="#readInt32%2CStream" title="readInt32(s: Stream): int32">readInt32(s: Stream): int32</a></li>
  204. </ul>
  205. <ul class="simple nested-toc-section">readInt64
  206. <li><a class="reference" href="#readInt64%2CStream" title="readInt64(s: Stream): int64">readInt64(s: Stream): int64</a></li>
  207. </ul>
  208. <ul class="simple nested-toc-section">readLine
  209. <li><a class="reference" href="#readLine%2CStream" title="readLine(s: Stream): string">readLine(s: Stream): string</a></li>
  210. <li><a class="reference" href="#readLine%2CStream%2Cstring" title="readLine(s: Stream; line: var string): bool">readLine(s: Stream; line: var string): bool</a></li>
  211. </ul>
  212. <ul class="simple nested-toc-section">readStr
  213. <li><a class="reference" href="#readStr%2CStream%2Cint" title="readStr(s: Stream; length: int): string">readStr(s: Stream; length: int): string</a></li>
  214. <li><a class="reference" href="#readStr%2CStream%2Cint%2Cstring" title="readStr(s: Stream; length: int; str: var string)">readStr(s: Stream; length: int; str: var string)</a></li>
  215. </ul>
  216. <ul class="simple nested-toc-section">readUint8
  217. <li><a class="reference" href="#readUint8%2CStream" title="readUint8(s: Stream): uint8">readUint8(s: Stream): uint8</a></li>
  218. </ul>
  219. <ul class="simple nested-toc-section">readUint16
  220. <li><a class="reference" href="#readUint16%2CStream" title="readUint16(s: Stream): uint16">readUint16(s: Stream): uint16</a></li>
  221. </ul>
  222. <ul class="simple nested-toc-section">readUint32
  223. <li><a class="reference" href="#readUint32%2CStream" title="readUint32(s: Stream): uint32">readUint32(s: Stream): uint32</a></li>
  224. </ul>
  225. <ul class="simple nested-toc-section">readUint64
  226. <li><a class="reference" href="#readUint64%2CStream" title="readUint64(s: Stream): uint64">readUint64(s: Stream): uint64</a></li>
  227. </ul>
  228. <ul class="simple nested-toc-section">setPosition
  229. <li><a class="reference" href="#setPosition%2CStream%2Cint" title="setPosition(s: Stream; pos: int)">setPosition(s: Stream; pos: int)</a></li>
  230. </ul>
  231. <ul class="simple nested-toc-section">write
  232. <li><a class="reference" href="#write%2CStream%2Cvarargs%5Bstring%2C%5D" title="write(s: Stream; args: varargs[string, `$`])">write(s: Stream; args: varargs[string, `$`])</a></li>
  233. <li><a class="reference" href="#write%2CStream%2Cstring" title="write(s: Stream; x: string)">write(s: Stream; x: string)</a></li>
  234. <li><a class="reference" href="#write%2CStream%2CT" title="write[T](s: Stream; x: T)">write[T](s: Stream; x: T)</a></li>
  235. </ul>
  236. <ul class="simple nested-toc-section">writeData
  237. <li><a class="reference" href="#writeData%2CStream%2Cpointer%2Cint" title="writeData(s: Stream; buffer: pointer; bufLen: int)">writeData(s: Stream; buffer: pointer; bufLen: int)</a></li>
  238. </ul>
  239. <ul class="simple nested-toc-section">writeLine
  240. <li><a class="reference" href="#writeLine%2CStream%2Cvarargs%5Bstring%2C%5D" title="writeLine(s: Stream; args: varargs[string, `$`])">writeLine(s: Stream; args: varargs[string, `$`])</a></li>
  241. </ul>
  242. </ul>
  243. </details>
  244. </li>
  245. <li>
  246. <details open>
  247. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  248. <ul class="simple simple-toc-section">
  249. <ul class="simple nested-toc-section">lines
  250. <li><a class="reference" href="#lines.i%2CStream" title="lines(s: Stream): string">lines(s: Stream): string</a></li>
  251. </ul>
  252. </ul>
  253. </details>
  254. </li>
  255. <li>
  256. <a class="reference reference-toplevel" href="#19" id="69">Exports</a>
  257. </li>
  258. </ul>
  259. </div>
  260. <div class="nine columns" id="content">
  261. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  262. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  263. <div id="tocRoot"></div>
  264. <p class="module-desc"><p>This module provides a stream interface and two implementations thereof: the <a class="reference external" href="#FileStream">FileStream</a> and the <a class="reference external" href="#StringStream">StringStream</a> which implement the stream interface for Nim file objects (<tt class="docutils literal"><span class="pre"><span class="Identifier">File</span></span></tt>) and strings.</p>
  265. <p>Other modules may provide other implementations for this standard stream interface.</p>
  266. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  267. Due to the use of <tt class="docutils literal"><span class="pre"><span class="Identifier">pointer</span></span></tt>, the <tt class="docutils literal"><span class="pre"><span class="Identifier">readData</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">peekData</span></span></tt> and</div>
  268. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">writeData</span></span></tt> interfaces are not available on the compile-time VM, and must be cast from a <tt class="docutils literal"><span class="pre"><span class="Keyword">ptr</span> <span class="Identifier">string</span></span></tt> on the JS backend. However, <tt class="docutils literal"><span class="pre"><span class="Identifier">readDataStr</span></span></tt> is available generally in place of <tt class="docutils literal"><span class="pre"><span class="Identifier">readData</span></span></tt>.</p>
  269. <h1><a class="toc-backref" id="basic-usage" href="#basic-usage">Basic usage</a></h1><p>The basic flow of using this module is:</p>
  270. <ol class="simple"><li>Open input stream</li>
  271. <li>Read or write stream</li>
  272. <li>Close stream</li>
  273. </ol>
  274. <h2><a class="toc-backref" id="basic-usage-stringstream-example" href="#basic-usage-stringstream-example">StringStream example</a></h2><p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
  275. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="LongStringLit">&quot;&quot;&quot;The first line
  276. the second line
  277. the third line&quot;&quot;&quot;</span><span class="Punctuation">)</span>
  278. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  279. <span class="Keyword">while</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  280. <span class="Identifier">echo</span> <span class="Identifier">line</span>
  281. <span class="Comment"># Output:</span>
  282. <span class="Comment"># The first line</span>
  283. <span class="Comment"># the second line</span>
  284. <span class="Comment"># the third line</span>
  285. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  286. <h2><a class="toc-backref" id="basic-usage-filestream-example" href="#basic-usage-filestream-example">FileStream example</a></h2><p>Write file stream example:</p>
  287. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
  288. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">,</span> <span class="Identifier">fmWrite</span><span class="Punctuation">)</span>
  289. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  290. <span class="Keyword">if</span> <span class="Keyword">not</span> <span class="Identifier">isNil</span><span class="Punctuation">(</span><span class="Identifier">strm</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  291. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line&quot;</span><span class="Punctuation">)</span>
  292. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">&quot;the second line&quot;</span><span class="Punctuation">)</span>
  293. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">&quot;the third line&quot;</span><span class="Punctuation">)</span>
  294. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  295. <span class="Comment"># Output (somefile.txt):</span>
  296. <span class="Comment"># The first line</span>
  297. <span class="Comment"># the second line</span>
  298. <span class="Comment"># the third line</span></pre></p>
  299. <p>Read file stream example:</p>
  300. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
  301. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">,</span> <span class="Identifier">fmRead</span><span class="Punctuation">)</span>
  302. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  303. <span class="Keyword">if</span> <span class="Keyword">not</span> <span class="Identifier">isNil</span><span class="Punctuation">(</span><span class="Identifier">strm</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  304. <span class="Keyword">while</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  305. <span class="Identifier">echo</span> <span class="Identifier">line</span>
  306. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  307. <span class="Comment"># Output:</span>
  308. <span class="Comment"># The first line</span>
  309. <span class="Comment"># the second line</span>
  310. <span class="Comment"># the third line</span></pre></p>
  311. <h1><a class="toc-backref" id="see-also" href="#see-also">See also</a></h1><ul class="simple"><li><a class="reference external" href="asyncstreams.html">asyncstreams module</a></li>
  312. <li><a class="reference external" href="syncio.html">io module</a> for <a class="reference external" href="syncio.html#FileMode">FileMode enum</a></li>
  313. </ul>
  314. </p>
  315. <div class="section" id="6">
  316. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  317. <dl class="item">
  318. <a class="reference external" href="since.html">since</a>, <a class="reference external" href="syncio.html">syncio</a>
  319. </dl>
  320. </div>
  321. <div class="section" id="7">
  322. <h1><a class="toc-backref" href="#7">Types</a></h1>
  323. <dl class="item">
  324. <div id="FileStream">
  325. <dt><pre><a href="streams.html#FileStream"><span class="Identifier">FileStream</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <a href="streams.html#FileStreamObj"><span class="Identifier">FileStreamObj</span></a></pre></dt>
  326. <dd>
  327. <p>A stream that encapsulates a <tt class="docutils literal"><span class="pre"><span class="Identifier">File</span></span></tt>.</p>
  328. <p><strong>Note:</strong> Not available for JS backend.</p>
  329. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1325" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  330. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1325" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  331. </dd>
  332. </div>
  333. <div id="FileStreamObj">
  334. <dt><pre><a href="streams.html#FileStreamObj"><span class="Identifier">FileStreamObj</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a></pre></dt>
  335. <dd>
  336. <p>A file stream object.</p>
  337. <p><strong>Note:</strong> Not available for JS backend.</p>
  338. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1329" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  339. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1329" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  340. </dd>
  341. </div>
  342. <div id="Stream">
  343. <dt><pre><a href="streams.html#Stream"><span class="Identifier">Stream</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <a href="streams.html#StreamObj"><span class="Identifier">StreamObj</span></a></pre></dt>
  344. <dd>
  345. All procedures of this module use this type. Procedures don't directly use <a class="reference external" href="#StreamObj">StreamObj</a>.
  346. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L113" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  347. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L113" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  348. </dd>
  349. </div>
  350. <div id="StreamObj">
  351. <dt><pre><a href="streams.html#StreamObj"><span class="Identifier">StreamObj</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="system.html#RootObj"><span class="Identifier">RootObj</span></a>
  352. <span class="Identifier">closeImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span> {.<span class="Identifier">nimcall</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><a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span>
  353. <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>.}
  354. <span class="Identifier">atEndImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">nimcall</span><span class="Other">,</span>
  355. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span>
  356. <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>.}
  357. <span class="Identifier">setPositionImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">pos</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span> {.<span class="Identifier">nimcall</span><span class="Other">,</span>
  358. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><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">gcsafe</span></span>.}
  359. <span class="Identifier">getPositionImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">nimcall</span><span class="Other">,</span>
  360. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><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">gcsafe</span></span>.}
  361. <span class="Identifier">readDataStrImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">buffer</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="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</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> {.
  362. <span class="Identifier">nimcall</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><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span> <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>.}
  363. <span class="Identifier">readLineImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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 class="Identifier">nimcall</span><span class="Other">,</span>
  364. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span> <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>.}
  365. <span class="Identifier">readDataImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">bufLen</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">nimcall</span><span class="Other">,</span>
  366. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span> <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>.}
  367. <span class="Identifier">peekDataImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">bufLen</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">nimcall</span><span class="Other">,</span>
  368. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span> <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>.}
  369. <span class="Identifier">writeDataImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">bufLen</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span> {.<span class="Identifier">nimcall</span><span class="Other">,</span>
  370. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span> <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>.}
  371. <span class="Identifier">flushImpl</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span> {.<span class="Identifier">nimcall</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><a href="system.html#Defect"><span class="Identifier">Defect</span></a><span class="Other">,</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a><span class="Other">,</span> <a href="exceptions.html#OSError"><span class="Identifier">OSError</span></a><span class="Other">]</span><span class="Other">,</span>
  372. <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>
  373. <dd>
  374. <p>Stream interface that supports writing or reading.</p>
  375. <p><strong>Note:</strong></p>
  376. <ul class="simple"><li>That these fields here shouldn't be used directly. They are accessible so that a stream implementation can override them.</li>
  377. </ul>
  378. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L116" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  379. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L116" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  380. </dd>
  381. </div>
  382. <div id="StringStream">
  383. <dt><pre><a href="streams.html#StringStream"><span class="Identifier">StringStream</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <a href="streams.html#StringStreamObj"><span class="Identifier">StringStreamObj</span></a></pre></dt>
  384. <dd>
  385. A stream that encapsulates a string.
  386. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1148" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  387. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1148" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  388. </dd>
  389. </div>
  390. <div id="StringStreamObj">
  391. <dt><pre><a href="streams.html#StringStreamObj"><span class="Identifier">StringStreamObj</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="streams.html#StreamObj"><span class="Identifier">StreamObj</span></a>
  392. <span class="Identifier">data</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Comment">## A string data.</span>
  393. <span class="Comment">## This is updated when called `writeLine` etc.</span></pre></dt>
  394. <dd>
  395. A string stream object.
  396. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1150" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  397. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1150" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  398. </dd>
  399. </div>
  400. </dl>
  401. </div>
  402. <div class="section" id="12">
  403. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  404. <dl class="item">
  405. <div id="atEnd-procs-all">
  406. <div id="atEnd,Stream">
  407. <dt><pre><span class="Keyword">proc</span> <a href="#atEnd%2CStream"><span class="Identifier">atEnd</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  408. <dd>
  409. Checks if more data can be read from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Returns <tt class="docutils literal"><span class="pre">true</span></tt> if all data has been read.
  410. <p><strong class="examples_text">Example:</strong></p>
  411. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  412. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  413. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">atEnd</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  414. <span class="Keyword">while</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  415. <span class="Keyword">discard</span>
  416. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">atEnd</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  417. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  418. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L197" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  419. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L197" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  420. </dd>
  421. </div>
  422. </div>
  423. <div id="close-procs-all">
  424. <div id="close,Stream">
  425. <dt><pre><span class="Keyword">proc</span> <a href="#close%2CStream"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span>
  426. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  427. <dd>
  428. <p>Closes the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  429. <p>See also:</p>
  430. <ul class="simple"><li><a class="reference external" href="#flush,Stream">flush proc</a></li>
  431. </ul>
  432. <p><strong class="examples_text">Example:</strong></p>
  433. <pre class="listing"><span class="Keyword">block</span><span class="Punctuation">:</span>
  434. <span class="Keyword">let</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  435. <span class="Comment">## do something...</span>
  436. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  437. <span class="Keyword">block</span><span class="Punctuation">:</span>
  438. <span class="Keyword">let</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;amissingfile.txt&quot;</span><span class="Punctuation">)</span>
  439. <span class="Comment"># deferring works even if newFileStream fails</span>
  440. <span class="Keyword">defer</span><span class="Punctuation">:</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  441. <span class="Keyword">if</span> <span class="Keyword">not</span> <span class="Identifier">isNil</span><span class="Punctuation">(</span><span class="Identifier">strm</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  442. <span class="Comment">## do something...</span></pre>
  443. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L176" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  444. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L176" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  445. </dd>
  446. </div>
  447. </div>
  448. <div id="flush-procs-all">
  449. <div id="flush,Stream">
  450. <dt><pre><span class="Keyword">proc</span> <a href="#flush%2CStream"><span class="Identifier">flush</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span>
  451. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  452. <dd>
  453. <p>Flushes the buffers that the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> might use.</p>
  454. <p>This procedure causes any unwritten data for that stream to be delivered to the host environment to be written to the file.</p>
  455. <p>See also:</p>
  456. <ul class="simple"><li><a class="reference external" href="#close,Stream">close proc</a></li>
  457. </ul>
  458. <p><strong class="examples_text">Example:</strong></p>
  459. <pre class="listing"><span class="Keyword">from</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">os</span> <span class="Keyword">import</span> <span class="Identifier">removeFile</span>
  460. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">,</span> <span class="Identifier">fmWrite</span><span class="Punctuation">)</span>
  461. <span class="Identifier">doAssert</span> <span class="StringLit">&quot;Before write:&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;Before write:&quot;</span>
  462. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">&quot;hello&quot;</span><span class="Punctuation">)</span>
  463. <span class="Identifier">doAssert</span> <span class="StringLit">&quot;After write:&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;After write:&quot;</span>
  464. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  465. <span class="Identifier">doAssert</span> <span class="StringLit">&quot;After flush:&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;After flush:hello&quot;</span>
  466. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">&quot;HELLO&quot;</span><span class="Punctuation">)</span>
  467. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  468. <span class="Identifier">doAssert</span> <span class="StringLit">&quot;After flush:&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;After flush:helloHELLO&quot;</span>
  469. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  470. <span class="Identifier">doAssert</span> <span class="StringLit">&quot;After close:&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;After close:helloHELLO&quot;</span>
  471. <span class="Identifier">removeFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span></pre>
  472. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L147" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  473. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L147" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  474. </dd>
  475. </div>
  476. </div>
  477. <div id="getPosition-procs-all">
  478. <div id="getPosition,Stream">
  479. <dt><pre><span class="Keyword">proc</span> <a href="#getPosition%2CStream"><span class="Identifier">getPosition</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  480. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  481. <dd>
  482. Retrieves the current position in the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
  483. <p><strong class="examples_text">Example:</strong></p>
  484. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  485. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">getPosition</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
  486. <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  487. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">getPosition</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">15</span>
  488. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  489. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L223" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  490. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L223" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  491. </dd>
  492. </div>
  493. </div>
  494. <div id="newFileStream-procs-all">
  495. <div id="newFileStream,File">
  496. <dt><pre><span class="Keyword">proc</span> <a href="#newFileStream%2CFile"><span class="Identifier">newFileStream</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> <span class="Identifier">owned</span> <span class="Identifier">FileStream</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  497. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  498. <dd>
  499. <p>Creates a new stream from the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>.</p>
  500. <p><strong>Note:</strong> Not available for JS backend.</p>
  501. <p>See also:</p>
  502. <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
  503. <li><a class="reference external" href="#newFileStream,string,FileMode,int">newFileStream proc</a> is the same as using <a class="reference external" href="syncio.html#open,File,string,FileMode,int">open proc</a> on Examples.</li>
  504. <li><a class="reference external" href="#openFileStream,string,FileMode,int">openFileStream proc</a> creates a file stream from the file name and the mode.</li>
  505. </ul>
  506. <p><strong class="examples_text">Example:</strong></p>
  507. <pre class="listing"><span class="Comment">## Input (somefile.txt):</span>
  508. <span class="Comment">## The first line</span>
  509. <span class="Comment">## the second line</span>
  510. <span class="Comment">## the third line</span>
  511. <span class="Keyword">var</span> <span class="Identifier">f</span><span class="Punctuation">:</span> <span class="Identifier">File</span>
  512. <span class="Keyword">if</span> <span class="Identifier">open</span><span class="Punctuation">(</span><span class="Identifier">f</span><span class="Punctuation">,</span> <span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">,</span> <span class="Identifier">fmRead</span><span class="Punctuation">,</span> <span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  513. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="Identifier">f</span><span class="Punctuation">)</span>
  514. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  515. <span class="Keyword">while</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  516. <span class="Identifier">echo</span> <span class="Identifier">line</span>
  517. <span class="Comment">## Output:</span>
  518. <span class="Comment">## The first line</span>
  519. <span class="Comment">## the second line</span>
  520. <span class="Comment">## the third line</span>
  521. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  522. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1362" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  523. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1362" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  524. </dd>
  525. </div>
  526. <div id="newFileStream,string,FileMode,int">
  527. <dt><pre><span class="Keyword">proc</span> <a href="#newFileStream%2Cstring%2CFileMode%2Cint"><span class="Identifier">newFileStream</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> <span class="Identifier">owned</span>
  528. <span class="Identifier">FileStream</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  529. <dd>
  530. <p>Creates a new stream from the file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> with the mode <tt class="docutils literal"><span class="pre"><span class="Identifier">mode</span></span></tt>.</p>
  531. <p>If the file cannot be opened, <tt class="docutils literal"><span class="pre"><span class="Keyword">nil</span></span></tt> is returned. See the <a class="reference external" href="syncio.html">io module</a> for a list of available <a class="reference external" href="syncio.html#FileMode">FileMode enums</a>.</p>
  532. <p><strong>Note:</strong></p>
  533. <ul class="simple"><li><strong>This function returns nil in case of failure.</strong> To prevent unexpected behavior and ensure proper error handling, use <a class="reference external" href="#openFileStream,string,FileMode,int">openFileStream proc</a> instead.</li>
  534. <li>Not available for JS backend.</li>
  535. </ul>
  536. <p>See also:</p>
  537. <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
  538. <li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
  539. <li><a class="reference external" href="#openFileStream,string,FileMode,int">openFileStream proc</a> creates a file stream from the file name and the mode.</li>
  540. </ul>
  541. <p><strong class="examples_text">Example:</strong></p>
  542. <pre class="listing"><span class="Keyword">from</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">os</span> <span class="Keyword">import</span> <span class="Identifier">removeFile</span>
  543. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">,</span> <span class="Identifier">fmWrite</span><span class="Punctuation">)</span>
  544. <span class="Keyword">if</span> <span class="Keyword">not</span> <span class="Identifier">isNil</span><span class="Punctuation">(</span><span class="Identifier">strm</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  545. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line&quot;</span><span class="Punctuation">)</span>
  546. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">&quot;the second line&quot;</span><span class="Punctuation">)</span>
  547. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">&quot;the third line&quot;</span><span class="Punctuation">)</span>
  548. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  549. <span class="Comment">## Output (somefile.txt)</span>
  550. <span class="Comment">## The first line</span>
  551. <span class="Comment">## the second line</span>
  552. <span class="Comment">## the third line</span>
  553. <span class="Identifier">removeFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span></pre>
  554. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1405" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  555. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1405" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  556. </dd>
  557. </div>
  558. </div>
  559. <div id="newStringStream-procs-all">
  560. <div id="newStringStream,sinkstring">
  561. <dt><pre><span class="Keyword">proc</span> <a href="#newStringStream%2Csinkstring"><span class="Identifier">newStringStream</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span> <span class="Identifier">StringStream</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>
  562. <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>
  563. <dd>
  564. <p>Creates a new stream from the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  565. <p>See also:</p>
  566. <ul class="simple"><li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
  567. <li><a class="reference external" href="#newFileStream,string,FileMode,int">newFileStream proc</a> creates a file stream from the file name and the mode.</li>
  568. <li><a class="reference external" href="#openFileStream,string,FileMode,int">openFileStream proc</a> creates a file stream from the file name and the mode.</li>
  569. </ul>
  570. <p><strong class="examples_text">Example:</strong></p>
  571. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  572. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  573. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;the second line&quot;</span>
  574. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;the third line&quot;</span>
  575. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  576. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1287" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  577. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1287" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  578. </dd>
  579. </div>
  580. </div>
  581. <div id="openFileStream-procs-all">
  582. <div id="openFileStream,string,FileMode,int">
  583. <dt><pre><span class="Keyword">proc</span> <a href="#openFileStream%2Cstring%2CFileMode%2Cint"><span class="Identifier">openFileStream</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> <span class="Identifier">owned</span>
  584. <span class="Identifier">FileStream</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>
  585. <dd>
  586. <p>Creates a new stream from the file named <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> with the mode <tt class="docutils literal"><span class="pre"><span class="Identifier">mode</span></span></tt>. If the file cannot be opened, an IO exception is raised.</p>
  587. <p><strong>Note:</strong> Not available for JS backend.</p>
  588. <p>See also:</p>
  589. <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
  590. <li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
  591. <li><a class="reference external" href="#newFileStream,string,FileMode,int">newFileStream proc</a> creates a file stream from the file name and the mode.</li>
  592. </ul>
  593. <p><strong class="examples_text">Example:</strong></p>
  594. <pre class="listing"><span class="Keyword">try</span><span class="Punctuation">:</span>
  595. <span class="Comment">## Input (somefile.txt):</span>
  596. <span class="Comment">## The first line</span>
  597. <span class="Comment">## the second line</span>
  598. <span class="Comment">## the third line</span>
  599. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">openFileStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span>
  600. <span class="Identifier">echo</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  601. <span class="Comment">## Output:</span>
  602. <span class="Comment">## The first line</span>
  603. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  604. <span class="Keyword">except</span><span class="Punctuation">:</span>
  605. <span class="Identifier">stderr</span><span class="Operator">.</span><span class="Identifier">write</span> <span class="Identifier">getCurrentExceptionMsg</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  606. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1444" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  607. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1444" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  608. </dd>
  609. </div>
  610. </div>
  611. <div id="peek-procs-all">
  612. <div id="peek,Stream,T">
  613. <dt><pre><span class="Keyword">proc</span> <a href="#peek%2CStream%2CT"><span class="Identifier">peek</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">)</span></pre></dt>
  614. <dd>
  615. <p>Generic peek procedure. Peeks <tt class="docutils literal"><span class="pre"><span class="Identifier">result</span></span></tt> from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  616. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  617. <p><strong class="examples_text">Example:</strong></p>
  618. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;012&quot;</span><span class="Punctuation">)</span>
  619. <span class="Comment">## peekInt</span>
  620. <span class="Keyword">var</span> <span class="Identifier">i</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
  621. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peek</span><span class="Punctuation">(</span><span class="Identifier">i</span><span class="Punctuation">)</span>
  622. <span class="Identifier">doAssert</span> <span class="Identifier">i</span> <span class="Operator">==</span> <span class="DecNumber">48</span>
  623. <span class="Comment">## peekData</span>
  624. <span class="Keyword">var</span> <span class="Identifier">buffer</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">char</span><span class="Punctuation">]</span>
  625. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peek</span><span class="Punctuation">(</span><span class="Identifier">buffer</span><span class="Punctuation">)</span>
  626. <span class="Identifier">doAssert</span> <span class="Identifier">buffer</span> <span class="Operator">==</span> <span class="Punctuation">[</span><span class="Punctuation">'</span><span class="DecNumber">0'</span><span class="Punctuation">,</span> <span class="CharLit">'1'</span><span class="Punctuation">]</span>
  627. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  628. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L433" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  629. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L433" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  630. </dd>
  631. </div>
  632. </div>
  633. <div id="peekBool-procs-all">
  634. <div id="peekBool,Stream">
  635. <dt><pre><span class="Keyword">proc</span> <a href="#peekBool%2CStream"><span class="Identifier">peekBool</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  636. <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>
  637. <dd>
  638. <p>Peeks a bool from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  639. <p>A bool is one byte long and it is <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> for every non-zero (<tt class="docutils literal"><span class="pre"><span class="DecNumber">0000_0000</span></span></tt>) value. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  640. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  641. <p><strong class="examples_text">Example:</strong></p>
  642. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  643. <span class="Comment">## setup for reading data</span>
  644. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="Identifier">true</span><span class="Punctuation">)</span>
  645. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="Identifier">false</span><span class="Punctuation">)</span>
  646. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  647. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  648. <span class="Comment">## get data</span>
  649. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekBool</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  650. <span class="Comment">## not false</span>
  651. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekBool</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  652. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readBool</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  653. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekBool</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  654. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  655. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L517" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  656. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L517" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  657. </dd>
  658. </div>
  659. </div>
  660. <div id="peekChar-procs-all">
  661. <div id="peekChar,Stream">
  662. <dt><pre><span class="Keyword">proc</span> <a href="#peekChar%2CStream"><span class="Identifier">peekChar</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  663. <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>
  664. <dd>
  665. Peeks a char from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred. Returns '\0' as an EOF marker.
  666. <p><strong class="examples_text">Example:</strong></p>
  667. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;12</span><span class="EscapeSequence">\n</span><span class="StringLit">3&quot;</span><span class="Punctuation">)</span>
  668. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'1'</span>
  669. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'1'</span>
  670. <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readAll</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  671. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'\x00'</span>
  672. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  673. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L473" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  674. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L473" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  675. </dd>
  676. </div>
  677. </div>
  678. <div id="peekData-procs-all">
  679. <div id="peekData,Stream,pointer,int">
  680. <dt><pre><span class="Keyword">proc</span> <a href="#peekData%2CStream%2Cpointer%2Cint"><span class="Identifier">peekData</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">bufLen</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  681. <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">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="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>
  682. <dd>
  683. <p>Low level proc that reads data into an untyped <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt> of <tt class="docutils literal"><span class="pre"><span class="Identifier">bufLen</span></span></tt> size without moving stream position.</p>
  684. <p><strong>JS note:</strong> <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt> is treated as a <tt class="docutils literal"><span class="pre">ptr string</span></tt> and written to between <tt class="docutils literal"><span class="pre">0..&lt;bufLen</span></tt>.</p>
  685. <p><strong class="examples_text">Example:</strong></p>
  686. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcde&quot;</span><span class="Punctuation">)</span>
  687. <span class="Keyword">var</span> <span class="Identifier">buffer</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="Identifier">char</span><span class="Punctuation">]</span>
  688. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekData</span><span class="Punctuation">(</span><span class="Keyword">addr</span><span class="Punctuation">(</span><span class="Identifier">buffer</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="DecNumber">1024</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
  689. <span class="Identifier">doAssert</span> <span class="Identifier">buffer</span> <span class="Operator">==</span> <span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">a</span><span class="CharLit">', '</span><span class="Identifier">b</span><span class="CharLit">', '</span><span class="Identifier">c</span><span class="CharLit">', '</span><span class="Identifier">d</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">', '</span><span class="Operator">\</span><span class="Identifier">x00</span><span class="CharLit">']</span>
  690. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">atEnd</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  691. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  692. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L313" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  693. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L313" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  694. </dd>
  695. </div>
  696. </div>
  697. <div id="peekFloat32-procs-all">
  698. <div id="peekFloat32,Stream">
  699. <dt><pre><span class="Keyword">proc</span> <a href="#peekFloat32%2CStream"><span class="Identifier">peekFloat32</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#float32"><span class="Identifier">float32</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</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">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>
  701. <dd>
  702. <p>Peeks a float32 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  703. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  704. <p><strong class="examples_text">Example:</strong></p>
  705. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  706. <span class="Comment">## setup for reading data</span>
  707. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">1'f32</span><span class="Punctuation">)</span>
  708. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">2'f32</span><span class="Punctuation">)</span>
  709. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  710. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  711. <span class="Comment">## get data</span>
  712. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekFloat32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f32</span>
  713. <span class="Comment">## not 2'f32</span>
  714. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekFloat32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f32</span>
  715. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f32</span>
  716. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekFloat32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">2'f32</span>
  717. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  718. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L884" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  719. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L884" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  720. </dd>
  721. </div>
  722. </div>
  723. <div id="peekFloat64-procs-all">
  724. <div id="peekFloat64,Stream">
  725. <dt><pre><span class="Keyword">proc</span> <a href="#peekFloat64%2CStream"><span class="Identifier">peekFloat64</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#float64"><span class="Identifier">float64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  726. <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>
  727. <dd>
  728. <p>Peeks a float64 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  729. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  730. <p><strong class="examples_text">Example:</strong></p>
  731. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  732. <span class="Comment">## setup for reading data</span>
  733. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">1'f64</span><span class="Punctuation">)</span>
  734. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">2'f64</span><span class="Punctuation">)</span>
  735. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  736. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  737. <span class="Comment">## get data</span>
  738. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekFloat64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f64</span>
  739. <span class="Comment">## not 2'f64</span>
  740. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekFloat64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f64</span>
  741. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f64</span>
  742. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekFloat64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">2'f64</span>
  743. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  744. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L924" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  745. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L924" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  746. </dd>
  747. </div>
  748. </div>
  749. <div id="peekInt8-procs-all">
  750. <div id="peekInt8,Stream">
  751. <dt><pre><span class="Keyword">proc</span> <a href="#peekInt8%2CStream"><span class="Identifier">peekInt8</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int8"><span class="Identifier">int8</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  752. <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>
  753. <dd>
  754. <p>Peeks an int8 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  755. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  756. <p><strong class="examples_text">Example:</strong></p>
  757. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  758. <span class="Comment">## setup for reading data</span>
  759. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i8</span><span class="Punctuation">)</span>
  760. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i8</span><span class="Punctuation">)</span>
  761. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  762. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  763. <span class="Comment">## get data</span>
  764. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i8</span>
  765. <span class="Comment">## not 2'i8</span>
  766. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i8</span>
  767. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i8</span>
  768. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i8</span>
  769. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  770. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L563" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  771. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L563" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  772. </dd>
  773. </div>
  774. </div>
  775. <div id="peekInt16-procs-all">
  776. <div id="peekInt16,Stream">
  777. <dt><pre><span class="Keyword">proc</span> <a href="#peekInt16%2CStream"><span class="Identifier">peekInt16</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int16"><span class="Identifier">int16</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  778. <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>
  779. <dd>
  780. <p>Peeks an int16 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  781. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  782. <p><strong class="examples_text">Example:</strong></p>
  783. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  784. <span class="Comment">## setup for reading data</span>
  785. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i16</span><span class="Punctuation">)</span>
  786. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i16</span><span class="Punctuation">)</span>
  787. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  788. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  789. <span class="Comment">## get data</span>
  790. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i16</span>
  791. <span class="Comment">## not 2'i16</span>
  792. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i16</span>
  793. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i16</span>
  794. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i16</span>
  795. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  796. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L603" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  797. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L603" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  798. </dd>
  799. </div>
  800. </div>
  801. <div id="peekInt32-procs-all">
  802. <div id="peekInt32,Stream">
  803. <dt><pre><span class="Keyword">proc</span> <a href="#peekInt32%2CStream"><span class="Identifier">peekInt32</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int32"><span class="Identifier">int32</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  804. <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>
  805. <dd>
  806. <p>Peeks an int32 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  807. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  808. <p><strong class="examples_text">Example:</strong></p>
  809. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  810. <span class="Comment">## setup for reading data</span>
  811. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i32</span><span class="Punctuation">)</span>
  812. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i32</span><span class="Punctuation">)</span>
  813. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  814. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  815. <span class="Comment">## get data</span>
  816. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i32</span>
  817. <span class="Comment">## not 2'i32</span>
  818. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i32</span>
  819. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i32</span>
  820. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i32</span>
  821. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  822. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L643" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  823. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L643" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  824. </dd>
  825. </div>
  826. </div>
  827. <div id="peekInt64-procs-all">
  828. <div id="peekInt64,Stream">
  829. <dt><pre><span class="Keyword">proc</span> <a href="#peekInt64%2CStream"><span class="Identifier">peekInt64</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int64"><span class="Identifier">int64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  830. <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>
  831. <dd>
  832. <p>Peeks an int64 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  833. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  834. <p><strong class="examples_text">Example:</strong></p>
  835. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  836. <span class="Comment">## setup for reading data</span>
  837. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i64</span><span class="Punctuation">)</span>
  838. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i64</span><span class="Punctuation">)</span>
  839. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  840. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  841. <span class="Comment">## get data</span>
  842. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i64</span>
  843. <span class="Comment">## not 2'i64</span>
  844. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i64</span>
  845. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i64</span>
  846. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekInt64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i64</span>
  847. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  848. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L683" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  849. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L683" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  850. </dd>
  851. </div>
  852. </div>
  853. <div id="peekLine-procs-all">
  854. <div id="peekLine,Stream">
  855. <dt><pre><span class="Keyword">proc</span> <a href="#peekLine%2CStream"><span class="Identifier">peekLine</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  856. <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>
  857. <dd>
  858. <p>Peeks a line from a stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  859. <p><strong>Note:</strong> This is not very efficient.</p>
  860. <p>See also:</p>
  861. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  862. <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  863. <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
  864. </ul>
  865. <p><strong class="examples_text">Example:</strong></p>
  866. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  867. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  868. <span class="Comment">## not &quot;the second line&quot;</span>
  869. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  870. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  871. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;the second line&quot;</span>
  872. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  873. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1106" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  874. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1106" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  875. </dd>
  876. </div>
  877. <div id="peekLine,Stream,string">
  878. <dt><pre><span class="Keyword">proc</span> <a href="#peekLine%2CStream%2Cstring"><span class="Identifier">peekLine</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  879. <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>
  880. <dd>
  881. <p>Peeks a line of text from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> must not be <tt class="docutils literal"><span class="pre">nil</span></tt>! May throw an IO exception.</p>
  882. <p>A line of text may be delimited by <tt class="docutils literal"><span class="pre">CR</span></tt>, <tt class="docutils literal"><span class="pre">LF</span></tt> or <tt class="docutils literal"><span class="pre">CRLF</span></tt>. The newline character(s) are not part of the returned string. Returns <tt class="docutils literal"><span class="pre">false</span></tt> if the end of the file has been reached, <tt class="docutils literal"><span class="pre">true</span></tt> otherwise. If <tt class="docutils literal"><span class="pre">false</span></tt> is returned <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> contains no new data.</p>
  883. <p>See also:</p>
  884. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  885. <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  886. <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
  887. </ul>
  888. <p><strong class="examples_text">Example:</strong></p>
  889. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  890. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  891. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  892. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  893. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  894. <span class="Comment">## not &quot;the second line&quot;</span>
  895. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  896. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  897. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  898. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  899. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;the second line&quot;</span>
  900. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  901. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1045" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  902. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1045" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  903. </dd>
  904. </div>
  905. </div>
  906. <div id="peekStr-procs-all">
  907. <div id="peekStr,Stream,int">
  908. <dt><pre><span class="Keyword">proc</span> <a href="#peekStr%2CStream%2Cint"><span class="Identifier">peekStr</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">length</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  909. <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>
  910. <dd>
  911. Peeks a string of length <tt class="docutils literal"><span class="pre"><span class="Identifier">length</span></span></tt> from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.
  912. <p><strong class="examples_text">Example:</strong></p>
  913. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcde&quot;</span><span class="Punctuation">)</span>
  914. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;ab&quot;</span>
  915. <span class="Comment">## not &quot;cd</span>
  916. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;ab&quot;</span>
  917. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;ab&quot;</span>
  918. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;cd&quot;</span>
  919. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  920. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L988" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  921. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L988" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  922. </dd>
  923. </div>
  924. <div id="peekStr,Stream,int,string">
  925. <dt><pre><span class="Keyword">proc</span> <a href="#peekStr%2CStream%2Cint%2Cstring"><span class="Identifier">peekStr</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">length</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">str</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> {.
  926. <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">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="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>
  927. <dd>
  928. Peeks a string of length <tt class="docutils literal"><span class="pre"><span class="Identifier">length</span></span></tt> from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.
  929. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L983" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  930. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L983" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  931. </dd>
  932. </div>
  933. </div>
  934. <div id="peekUint8-procs-all">
  935. <div id="peekUint8,Stream">
  936. <dt><pre><span class="Keyword">proc</span> <a href="#peekUint8%2CStream"><span class="Identifier">peekUint8</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint8"><span class="Identifier">uint8</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  937. <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>
  938. <dd>
  939. <p>Peeks an uint8 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  940. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  941. <p><strong class="examples_text">Example:</strong></p>
  942. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  943. <span class="Comment">## setup for reading data</span>
  944. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
  945. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
  946. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  947. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  948. <span class="Comment">## get data</span>
  949. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u8</span>
  950. <span class="Comment">## not 2'u8</span>
  951. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u8</span>
  952. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u8</span>
  953. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u8</span>
  954. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  955. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L723" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  956. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L723" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  957. </dd>
  958. </div>
  959. </div>
  960. <div id="peekUint16-procs-all">
  961. <div id="peekUint16,Stream">
  962. <dt><pre><span class="Keyword">proc</span> <a href="#peekUint16%2CStream"><span class="Identifier">peekUint16</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint16"><span class="Identifier">uint16</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  963. <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>
  964. <dd>
  965. <p>Peeks an uint16 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  966. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  967. <p><strong class="examples_text">Example:</strong></p>
  968. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  969. <span class="Comment">## setup for reading data</span>
  970. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u16</span><span class="Punctuation">)</span>
  971. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u16</span><span class="Punctuation">)</span>
  972. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  973. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  974. <span class="Comment">## get data</span>
  975. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u16</span>
  976. <span class="Comment">## not 2'u16</span>
  977. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u16</span>
  978. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u16</span>
  979. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u16</span>
  980. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  981. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L763" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  982. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L763" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  983. </dd>
  984. </div>
  985. </div>
  986. <div id="peekUint32-procs-all">
  987. <div id="peekUint32,Stream">
  988. <dt><pre><span class="Keyword">proc</span> <a href="#peekUint32%2CStream"><span class="Identifier">peekUint32</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint32"><span class="Identifier">uint32</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  989. <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>
  990. <dd>
  991. <p>Peeks an uint32 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  992. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  993. <p><strong class="examples_text">Example:</strong></p>
  994. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  995. <span class="Comment">## setup for reading data</span>
  996. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u32</span><span class="Punctuation">)</span>
  997. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u32</span><span class="Punctuation">)</span>
  998. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  999. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1000. <span class="Comment">## get data</span>
  1001. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u32</span>
  1002. <span class="Comment">## not 2'u32</span>
  1003. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u32</span>
  1004. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u32</span>
  1005. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u32</span>
  1006. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1007. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L804" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1008. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L804" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1009. </dd>
  1010. </div>
  1011. </div>
  1012. <div id="peekUint64-procs-all">
  1013. <div id="peekUint64,Stream">
  1014. <dt><pre><span class="Keyword">proc</span> <a href="#peekUint64%2CStream"><span class="Identifier">peekUint64</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint64"><span class="Identifier">uint64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1015. <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>
  1016. <dd>
  1017. <p>Peeks an uint64 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1018. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  1019. <p><strong class="examples_text">Example:</strong></p>
  1020. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1021. <span class="Comment">## setup for reading data</span>
  1022. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u64</span><span class="Punctuation">)</span>
  1023. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u64</span><span class="Punctuation">)</span>
  1024. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1025. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1026. <span class="Comment">## get data</span>
  1027. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u64</span>
  1028. <span class="Comment">## not 2'u64</span>
  1029. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u64</span>
  1030. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u64</span>
  1031. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">peekUint64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u64</span>
  1032. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1033. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L844" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1034. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L844" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1035. </dd>
  1036. </div>
  1037. </div>
  1038. <div id="read-procs-all">
  1039. <div id="read,Stream,T">
  1040. <dt><pre><span class="Keyword">proc</span> <a href="#read%2CStream%2CT"><span class="Identifier">read</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">)</span></pre></dt>
  1041. <dd>
  1042. <p>Generic read procedure. Reads <tt class="docutils literal"><span class="pre"><span class="Identifier">result</span></span></tt> from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  1043. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1044. <p><strong class="examples_text">Example:</strong></p>
  1045. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;012&quot;</span><span class="Punctuation">)</span>
  1046. <span class="Comment">## readInt</span>
  1047. <span class="Keyword">var</span> <span class="Identifier">i</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
  1048. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">read</span><span class="Punctuation">(</span><span class="Identifier">i</span><span class="Punctuation">)</span>
  1049. <span class="Identifier">doAssert</span> <span class="Identifier">i</span> <span class="Operator">==</span> <span class="DecNumber">48</span>
  1050. <span class="Comment">## readData</span>
  1051. <span class="Keyword">var</span> <span class="Identifier">buffer</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">char</span><span class="Punctuation">]</span>
  1052. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">read</span><span class="Punctuation">(</span><span class="Identifier">buffer</span><span class="Punctuation">)</span>
  1053. <span class="Identifier">doAssert</span> <span class="Identifier">buffer</span> <span class="Operator">==</span> <span class="Punctuation">[</span><span class="Punctuation">'</span><span class="DecNumber">1'</span><span class="Punctuation">,</span> <span class="CharLit">'2'</span><span class="Punctuation">]</span>
  1054. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1055. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L414" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1056. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L414" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1057. </dd>
  1058. </div>
  1059. </div>
  1060. <div id="readAll-procs-all">
  1061. <div id="readAll,Stream">
  1062. <dt><pre><span class="Keyword">proc</span> <a href="#readAll%2CStream"><span class="Identifier">readAll</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1063. <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>
  1064. <dd>
  1065. Reads all available data.
  1066. <p><strong class="examples_text">Example:</strong></p>
  1067. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  1068. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readAll</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span>
  1069. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">atEnd</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  1070. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1071. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L280" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1072. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L280" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1073. </dd>
  1074. </div>
  1075. </div>
  1076. <div id="readBool-procs-all">
  1077. <div id="readBool,Stream">
  1078. <dt><pre><span class="Keyword">proc</span> <a href="#readBool%2CStream"><span class="Identifier">readBool</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1079. <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>
  1080. <dd>
  1081. <p>Reads a bool from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  1082. <p>A bool is one byte long and it is <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> for every non-zero (<tt class="docutils literal"><span class="pre"><span class="DecNumber">0000_0000</span></span></tt>) value. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1083. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1084. <p><strong class="examples_text">Example:</strong></p>
  1085. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1086. <span class="Comment">## setup for reading data</span>
  1087. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="Identifier">true</span><span class="Punctuation">)</span>
  1088. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="Identifier">false</span><span class="Punctuation">)</span>
  1089. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1090. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1091. <span class="Comment">## get data</span>
  1092. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readBool</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  1093. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readBool</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  1094. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readBool</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1095. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1096. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L492" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1097. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L492" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1098. </dd>
  1099. </div>
  1100. </div>
  1101. <div id="readChar-procs-all">
  1102. <div id="readChar,Stream">
  1103. <dt><pre><span class="Keyword">proc</span> <a href="#readChar%2CStream"><span class="Identifier">readChar</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1104. <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>
  1105. <dd>
  1106. <p>Reads a char from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  1107. <p>Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred. Returns '\0' as an EOF marker.</p>
  1108. <p><strong class="examples_text">Example:</strong></p>
  1109. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;12</span><span class="EscapeSequence">\n</span><span class="StringLit">3&quot;</span><span class="Punctuation">)</span>
  1110. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'1'</span>
  1111. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'2'</span>
  1112. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'\n'</span>
  1113. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'3'</span>
  1114. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readChar</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'\x00'</span>
  1115. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1116. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L452" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1117. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L452" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1118. </dd>
  1119. </div>
  1120. </div>
  1121. <div id="readData-procs-all">
  1122. <div id="readData,Stream,pointer,int">
  1123. <dt><pre><span class="Keyword">proc</span> <a href="#readData%2CStream%2Cpointer%2Cint"><span class="Identifier">readData</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">bufLen</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  1124. <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">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="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>
  1125. <dd>
  1126. <p>Low level proc that reads data into an untyped <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt> of <tt class="docutils literal"><span class="pre"><span class="Identifier">bufLen</span></span></tt> size.</p>
  1127. <p><strong>JS note:</strong> <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt> is treated as a <tt class="docutils literal"><span class="pre">ptr string</span></tt> and written to between <tt class="docutils literal"><span class="pre">0..&lt;bufLen</span></tt>.</p>
  1128. <p><strong class="examples_text">Example:</strong></p>
  1129. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcde&quot;</span><span class="Punctuation">)</span>
  1130. <span class="Keyword">var</span> <span class="Identifier">buffer</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="Identifier">char</span><span class="Punctuation">]</span>
  1131. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readData</span><span class="Punctuation">(</span><span class="Keyword">addr</span><span class="Punctuation">(</span><span class="Identifier">buffer</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="DecNumber">1024</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
  1132. <span class="Identifier">doAssert</span> <span class="Identifier">buffer</span> <span class="Operator">==</span> <span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">a</span><span class="CharLit">', '</span><span class="Identifier">b</span><span class="CharLit">', '</span><span class="Identifier">c</span><span class="CharLit">', '</span><span class="Identifier">d</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">', '</span><span class="Operator">\</span><span class="Identifier">x00</span><span class="CharLit">']</span>
  1133. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">atEnd</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  1134. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1135. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L234" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1136. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L234" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1137. </dd>
  1138. </div>
  1139. </div>
  1140. <div id="readDataStr-procs-all">
  1141. <div id="readDataStr,Stream,string,Slice[int]">
  1142. <dt><pre><span class="Keyword">proc</span> <a href="#readDataStr%2CStream%2Cstring%2CSlice%5Bint%5D"><span class="Identifier">readDataStr</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">buffer</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="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</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> {.
  1143. <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">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="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>
  1144. <dd>
  1145. Low level proc that reads data into a string <tt class="docutils literal"><span class="pre">buffer</span></tt> at <tt class="docutils literal"><span class="pre">slice</span></tt>.
  1146. <p><strong class="examples_text">Example:</strong></p>
  1147. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcde&quot;</span><span class="Punctuation">)</span>
  1148. <span class="Keyword">var</span> <span class="Identifier">buffer</span> <span class="Operator">=</span> <span class="StringLit">&quot;12345&quot;</span>
  1149. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readDataStr</span><span class="Punctuation">(</span><span class="Identifier">buffer</span><span class="Punctuation">,</span> <span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
  1150. <span class="Identifier">doAssert</span> <span class="Identifier">buffer</span> <span class="Operator">==</span> <span class="StringLit">&quot;abcd5&quot;</span>
  1151. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1152. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L249" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1153. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L249" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1154. </dd>
  1155. </div>
  1156. </div>
  1157. <div id="readFloat32-procs-all">
  1158. <div id="readFloat32,Stream">
  1159. <dt><pre><span class="Keyword">proc</span> <a href="#readFloat32%2CStream"><span class="Identifier">readFloat32</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#float32"><span class="Identifier">float32</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1160. <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>
  1161. <dd>
  1162. <p>Reads a float32 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1163. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1164. <p><strong class="examples_text">Example:</strong></p>
  1165. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1166. <span class="Comment">## setup for reading data</span>
  1167. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">1'f32</span><span class="Punctuation">)</span>
  1168. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">2'f32</span><span class="Punctuation">)</span>
  1169. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1170. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1171. <span class="Comment">## get data</span>
  1172. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f32</span>
  1173. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">2'f32</span>
  1174. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat32</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1175. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1176. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L865" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1177. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L865" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1178. </dd>
  1179. </div>
  1180. </div>
  1181. <div id="readFloat64-procs-all">
  1182. <div id="readFloat64,Stream">
  1183. <dt><pre><span class="Keyword">proc</span> <a href="#readFloat64%2CStream"><span class="Identifier">readFloat64</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#float64"><span class="Identifier">float64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1184. <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>
  1185. <dd>
  1186. <p>Reads a float64 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1187. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1188. <p><strong class="examples_text">Example:</strong></p>
  1189. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1190. <span class="Comment">## setup for reading data</span>
  1191. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">1'f64</span><span class="Punctuation">)</span>
  1192. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="FloatNumber">2'f64</span><span class="Punctuation">)</span>
  1193. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1194. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1195. <span class="Comment">## get data</span>
  1196. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">1'f64</span>
  1197. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="FloatNumber">2'f64</span>
  1198. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readFloat64</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1199. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1200. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L905" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1201. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L905" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1202. </dd>
  1203. </div>
  1204. </div>
  1205. <div id="readInt8-procs-all">
  1206. <div id="readInt8,Stream">
  1207. <dt><pre><span class="Keyword">proc</span> <a href="#readInt8%2CStream"><span class="Identifier">readInt8</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int8"><span class="Identifier">int8</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1208. <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>
  1209. <dd>
  1210. <p>Reads an int8 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1211. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1212. <p><strong class="examples_text">Example:</strong></p>
  1213. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1214. <span class="Comment">## setup for reading data</span>
  1215. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i8</span><span class="Punctuation">)</span>
  1216. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i8</span><span class="Punctuation">)</span>
  1217. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1218. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1219. <span class="Comment">## get data</span>
  1220. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i8</span>
  1221. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i8</span>
  1222. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt8</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1223. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1224. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L544" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1225. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L544" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1226. </dd>
  1227. </div>
  1228. </div>
  1229. <div id="readInt16-procs-all">
  1230. <div id="readInt16,Stream">
  1231. <dt><pre><span class="Keyword">proc</span> <a href="#readInt16%2CStream"><span class="Identifier">readInt16</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int16"><span class="Identifier">int16</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1232. <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>
  1233. <dd>
  1234. <p>Reads an int16 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1235. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1236. <p><strong class="examples_text">Example:</strong></p>
  1237. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1238. <span class="Comment">## setup for reading data</span>
  1239. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i16</span><span class="Punctuation">)</span>
  1240. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i16</span><span class="Punctuation">)</span>
  1241. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1242. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1243. <span class="Comment">## get data</span>
  1244. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i16</span>
  1245. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i16</span>
  1246. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt16</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1247. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1248. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L584" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1249. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L584" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1250. </dd>
  1251. </div>
  1252. </div>
  1253. <div id="readInt32-procs-all">
  1254. <div id="readInt32,Stream">
  1255. <dt><pre><span class="Keyword">proc</span> <a href="#readInt32%2CStream"><span class="Identifier">readInt32</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int32"><span class="Identifier">int32</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1256. <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>
  1257. <dd>
  1258. <p>Reads an int32 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1259. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1260. <p><strong class="examples_text">Example:</strong></p>
  1261. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1262. <span class="Comment">## setup for reading data</span>
  1263. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i32</span><span class="Punctuation">)</span>
  1264. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i32</span><span class="Punctuation">)</span>
  1265. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1266. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1267. <span class="Comment">## get data</span>
  1268. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i32</span>
  1269. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i32</span>
  1270. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt32</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1271. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1272. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L624" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1273. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L624" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1274. </dd>
  1275. </div>
  1276. </div>
  1277. <div id="readInt64-procs-all">
  1278. <div id="readInt64,Stream">
  1279. <dt><pre><span class="Keyword">proc</span> <a href="#readInt64%2CStream"><span class="Identifier">readInt64</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int64"><span class="Identifier">int64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1280. <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>
  1281. <dd>
  1282. <p>Reads an int64 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1283. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1284. <p><strong class="examples_text">Example:</strong></p>
  1285. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1286. <span class="Comment">## setup for reading data</span>
  1287. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'i64</span><span class="Punctuation">)</span>
  1288. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'i64</span><span class="Punctuation">)</span>
  1289. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1290. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1291. <span class="Comment">## get data</span>
  1292. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'i64</span>
  1293. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'i64</span>
  1294. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readInt64</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1295. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1296. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L664" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1297. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L664" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1298. </dd>
  1299. </div>
  1300. </div>
  1301. <div id="readLine-procs-all">
  1302. <div id="readLine,Stream">
  1303. <dt><pre><span class="Keyword">proc</span> <a href="#readLine%2CStream"><span class="Identifier">readLine</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1304. <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>
  1305. <dd>
  1306. <p>Reads a line from a stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1307. <p><strong>Note:</strong> This is not very efficient.</p>
  1308. <p>See also:</p>
  1309. <ul class="simple"><li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  1310. <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
  1311. <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
  1312. </ul>
  1313. <p><strong class="examples_text">Example:</strong></p>
  1314. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  1315. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  1316. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;the second line&quot;</span>
  1317. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;the third line&quot;</span>
  1318. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1319. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1320. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1076" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1321. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1076" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1322. </dd>
  1323. </div>
  1324. <div id="readLine,Stream,string">
  1325. <dt><pre><span class="Keyword">proc</span> <a href="#readLine%2CStream%2Cstring"><span class="Identifier">readLine</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1326. <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>
  1327. <dd>
  1328. <p>Reads a line of text from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> must not be <tt class="docutils literal"><span class="pre">nil</span></tt>! May throw an IO exception.</p>
  1329. <p>A line of text may be delimited by <tt class="docutils literal"><span class="pre">LF</span></tt> or <tt class="docutils literal"><span class="pre">CRLF</span></tt>. The newline character(s) are not part of the returned string. Returns <tt class="docutils literal"><span class="pre">false</span></tt> if the end of the file has been reached, <tt class="docutils literal"><span class="pre">true</span></tt> otherwise. If <tt class="docutils literal"><span class="pre">false</span></tt> is returned <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt> contains no new data.</p>
  1330. <p>See also:</p>
  1331. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  1332. <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
  1333. <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
  1334. </ul>
  1335. <p><strong class="examples_text">Example:</strong></p>
  1336. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  1337. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  1338. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  1339. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  1340. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  1341. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;the second line&quot;</span>
  1342. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  1343. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;the third line&quot;</span>
  1344. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  1345. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;&quot;</span>
  1346. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1347. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1002" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1348. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1002" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1349. </dd>
  1350. </div>
  1351. </div>
  1352. <div id="readStr-procs-all">
  1353. <div id="readStr,Stream,int">
  1354. <dt><pre><span class="Keyword">proc</span> <a href="#readStr%2CStream%2Cint"><span class="Identifier">readStr</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">length</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1355. <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>
  1356. <dd>
  1357. Reads a string of length <tt class="docutils literal"><span class="pre"><span class="Identifier">length</span></span></tt> from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.
  1358. <p><strong class="examples_text">Example:</strong></p>
  1359. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcde&quot;</span><span class="Punctuation">)</span>
  1360. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;ab&quot;</span>
  1361. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;cd&quot;</span>
  1362. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;e&quot;</span>
  1363. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readStr</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;&quot;</span>
  1364. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1365. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L962" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1366. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L962" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1367. </dd>
  1368. </div>
  1369. <div id="readStr,Stream,int,string">
  1370. <dt><pre><span class="Keyword">proc</span> <a href="#readStr%2CStream%2Cint%2Cstring"><span class="Identifier">readStr</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">length</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">str</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> {.
  1371. <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">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="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>
  1372. <dd>
  1373. Reads a string of length <tt class="docutils literal"><span class="pre"><span class="Identifier">length</span></span></tt> from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.
  1374. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L957" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1375. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L957" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1376. </dd>
  1377. </div>
  1378. </div>
  1379. <div id="readUint8-procs-all">
  1380. <div id="readUint8,Stream">
  1381. <dt><pre><span class="Keyword">proc</span> <a href="#readUint8%2CStream"><span class="Identifier">readUint8</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint8"><span class="Identifier">uint8</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1382. <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>
  1383. <dd>
  1384. <p>Reads an uint8 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1385. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1386. <p><strong class="examples_text">Example:</strong></p>
  1387. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1388. <span class="Comment">## setup for reading data</span>
  1389. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
  1390. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
  1391. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1392. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1393. <span class="Comment">## get data</span>
  1394. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u8</span>
  1395. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint8</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u8</span>
  1396. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint8</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1397. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1398. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L704" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1399. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L704" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1400. </dd>
  1401. </div>
  1402. </div>
  1403. <div id="readUint16-procs-all">
  1404. <div id="readUint16,Stream">
  1405. <dt><pre><span class="Keyword">proc</span> <a href="#readUint16%2CStream"><span class="Identifier">readUint16</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint16"><span class="Identifier">uint16</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1406. <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>
  1407. <dd>
  1408. <p>Reads an uint16 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1409. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1410. <p><strong class="examples_text">Example:</strong></p>
  1411. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1412. <span class="Comment">## setup for reading data</span>
  1413. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u16</span><span class="Punctuation">)</span>
  1414. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u16</span><span class="Punctuation">)</span>
  1415. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1416. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1417. <span class="Comment">## get data</span>
  1418. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u16</span>
  1419. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint16</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u16</span>
  1420. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint16</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1421. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1422. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L744" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1423. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L744" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1424. </dd>
  1425. </div>
  1426. </div>
  1427. <div id="readUint32-procs-all">
  1428. <div id="readUint32,Stream">
  1429. <dt><pre><span class="Keyword">proc</span> <a href="#readUint32%2CStream"><span class="Identifier">readUint32</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint32"><span class="Identifier">uint32</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1430. <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>
  1431. <dd>
  1432. <p>Reads an uint32 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1433. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1434. <p><strong class="examples_text">Example:</strong></p>
  1435. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1436. <span class="Comment">## setup for reading data</span>
  1437. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u32</span><span class="Punctuation">)</span>
  1438. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u32</span><span class="Punctuation">)</span>
  1439. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1440. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1441. <span class="Comment">## get data</span>
  1442. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u32</span>
  1443. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint32</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u32</span>
  1444. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint32</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1445. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1446. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L784" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1447. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L784" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1448. </dd>
  1449. </div>
  1450. </div>
  1451. <div id="readUint64-procs-all">
  1452. <div id="readUint64,Stream">
  1453. <dt><pre><span class="Keyword">proc</span> <a href="#readUint64%2CStream"><span class="Identifier">readUint64</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#uint64"><span class="Identifier">uint64</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1454. <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>
  1455. <dd>
  1456. <p>Reads an uint64 from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurred.</p>
  1457. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1458. <p><strong class="examples_text">Example:</strong></p>
  1459. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1460. <span class="Comment">## setup for reading data</span>
  1461. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u64</span><span class="Punctuation">)</span>
  1462. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u64</span><span class="Punctuation">)</span>
  1463. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1464. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1465. <span class="Comment">## get data</span>
  1466. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1'</span><span class="Identifier">u64</span>
  1467. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint64</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2'</span><span class="Identifier">u64</span>
  1468. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IOError</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Keyword">discard</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readUint64</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1469. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1470. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L825" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1471. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L825" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1472. </dd>
  1473. </div>
  1474. </div>
  1475. <div id="setPosition-procs-all">
  1476. <div id="setPosition,Stream,int">
  1477. <dt><pre><span class="Keyword">proc</span> <a href="#setPosition%2CStream%2Cint"><span class="Identifier">setPosition</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">pos</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  1478. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1479. <dd>
  1480. Sets the position <tt class="docutils literal"><span class="pre"><span class="Identifier">pos</span></span></tt> of the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
  1481. <p><strong class="examples_text">Example:</strong></p>
  1482. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  1483. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">4</span><span class="Punctuation">)</span>
  1484. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;first line&quot;</span>
  1485. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1486. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  1487. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1488. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L211" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1489. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L211" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1490. </dd>
  1491. </div>
  1492. </div>
  1493. <div id="write-procs-all">
  1494. <div id="write,Stream,varargs[string,]">
  1495. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CStream%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">args</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1496. <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>
  1497. <dd>
  1498. Writes one or more strings to the the stream. No length fields or terminating zeros are written.
  1499. <p><strong class="examples_text">Example:</strong></p>
  1500. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span>
  1501. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">)</span>
  1502. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1503. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;1234&quot;</span>
  1504. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1505. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L388" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1506. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L388" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1507. </dd>
  1508. </div>
  1509. <div id="write,Stream,string">
  1510. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CStream%2Cstring"><span class="Identifier">write</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">x</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1511. <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>
  1512. <dd>
  1513. Writes the string <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> to the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. No length field or terminating zero is written.
  1514. <p><strong class="examples_text">Example:</strong></p>
  1515. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span>
  1516. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">&quot;THE FIRST LINE&quot;</span><span class="Punctuation">)</span>
  1517. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1518. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readLine</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;THE FIRST LINE&quot;</span>
  1519. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1520. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L368" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1521. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L368" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1522. </dd>
  1523. </div>
  1524. <div id="write,Stream,T">
  1525. <dt><pre><span class="Keyword">proc</span> <a href="#write%2CStream%2CT"><span class="Identifier">write</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span></pre></dt>
  1526. <dd>
  1527. <p>Generic write procedure. Writes <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> to the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Implementation:</p>
  1528. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#write,Stream,string">write(Stream, string)</a> for now.</p>
  1529. <p><pre class="listing"><span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">writeData</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">,</span> <span class="Identifier">unsafeAddr</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Identifier">sizeof</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre></p>
  1530. <p><strong class="examples_text">Example:</strong></p>
  1531. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span>
  1532. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcde&quot;</span><span class="Punctuation">)</span>
  1533. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1534. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readAll</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;abcde&quot;</span>
  1535. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1536. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L350" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1537. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L350" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1538. </dd>
  1539. </div>
  1540. </div>
  1541. <div id="writeData-procs-all">
  1542. <div id="writeData,Stream,pointer,int">
  1543. <dt><pre><span class="Keyword">proc</span> <a href="#writeData%2CStream%2Cpointer%2Cint"><span class="Identifier">writeData</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">bufLen</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span> {.
  1544. <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">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="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>
  1545. <dd>
  1546. <p>Low level proc that writes an untyped <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt> of <tt class="docutils literal"><span class="pre"><span class="Identifier">bufLen</span></span></tt> size to the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  1547. <p><strong>JS note:</strong> <tt class="docutils literal"><span class="pre"><span class="Identifier">buffer</span></span></tt> is treated as a <tt class="docutils literal"><span class="pre">ptr string</span></tt> and read between <tt class="docutils literal"><span class="pre">0..&lt;bufLen</span></tt>.</p>
  1548. <p><strong class="examples_text">Example:</strong></p>
  1549. <pre class="listing"><span class="Comment">## writeData</span>
  1550. <span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span>
  1551. <span class="Keyword">var</span> <span class="Identifier">buffer</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">a</span><span class="CharLit">', '</span><span class="Identifier">b</span><span class="CharLit">', '</span><span class="Identifier">c</span><span class="CharLit">', '</span><span class="Identifier">d</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">']</span>
  1552. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeData</span><span class="Punctuation">(</span><span class="Keyword">addr</span><span class="Punctuation">(</span><span class="Identifier">buffer</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Identifier">sizeof</span><span class="Punctuation">(</span><span class="Identifier">buffer</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  1553. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">atEnd</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  1554. <span class="Comment">## readData</span>
  1555. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1556. <span class="Keyword">var</span> <span class="Identifier">buffer2</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="Identifier">char</span><span class="Punctuation">]</span>
  1557. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readData</span><span class="Punctuation">(</span><span class="Keyword">addr</span><span class="Punctuation">(</span><span class="Identifier">buffer2</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Identifier">sizeof</span><span class="Punctuation">(</span><span class="Identifier">buffer2</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
  1558. <span class="Identifier">doAssert</span> <span class="Identifier">buffer2</span> <span class="Operator">==</span> <span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">a</span><span class="CharLit">', '</span><span class="Identifier">b</span><span class="CharLit">', '</span><span class="Identifier">c</span><span class="CharLit">', '</span><span class="Identifier">d</span><span class="CharLit">', '</span><span class="Identifier">e</span><span class="CharLit">', '</span><span class="Operator">\</span><span class="Identifier">x00</span><span class="CharLit">']</span>
  1559. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1560. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L329" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1561. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L329" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1562. </dd>
  1563. </div>
  1564. </div>
  1565. <div id="writeLine-procs-all">
  1566. <div id="writeLine,Stream,varargs[string,]">
  1567. <dt><pre><span class="Keyword">proc</span> <a href="#writeLine%2CStream%2Cvarargs%5Bstring%2C%5D"><span class="Identifier">writeLine</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">args</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> {.
  1568. <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">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="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>
  1569. <dd>
  1570. Writes one or more strings to the the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> followed by a new line. No length field or terminating zero is written.
  1571. <p><strong class="examples_text">Example:</strong></p>
  1572. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span>
  1573. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span>
  1574. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">)</span>
  1575. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">setPosition</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
  1576. <span class="Identifier">doAssert</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">readAll</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;12</span><span class="EscapeSequence">\n</span><span class="StringLit">34</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span>
  1577. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1578. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L400" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1579. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L400" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1580. </dd>
  1581. </div>
  1582. </div>
  1583. </dl>
  1584. </div>
  1585. <div class="section" id="15">
  1586. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  1587. <dl class="item">
  1588. <div id="lines-iterators-all">
  1589. <div id="lines.i,Stream">
  1590. <dt><pre><span class="Keyword">iterator</span> <a href="#lines.i%2CStream"><span class="Identifier">lines</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</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">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  1591. <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>
  1592. <dd>
  1593. <p>Iterates over every line in the stream. The iteration is based on <tt class="docutils literal"><span class="pre">readLine</span></tt>.</p>
  1594. <p>See also:</p>
  1595. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  1596. <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  1597. </ul>
  1598. <p><strong class="examples_text">Example:</strong></p>
  1599. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">strm</span> <span class="Operator">=</span> <span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="StringLit">&quot;The first line</span><span class="EscapeSequence">\n</span><span class="StringLit">the second line</span><span class="EscapeSequence">\n</span><span class="StringLit">the third line&quot;</span><span class="Punctuation">)</span>
  1600. <span class="Keyword">var</span> <span class="Identifier">lines</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span>
  1601. <span class="Keyword">for</span> <span class="Identifier">line</span> <span class="Keyword">in</span> <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">lines</span><span class="Punctuation">(</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  1602. <span class="Identifier">lines</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">line</span>
  1603. <span class="Identifier">doAssert</span> <span class="Identifier">lines</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">&quot;The first line&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;the second line&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;the third line&quot;</span><span class="Punctuation">]</span>
  1604. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1605. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1128" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1606. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1128" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1607. </dd>
  1608. </div>
  1609. </div>
  1610. </dl>
  1611. </div>
  1612. <div class="section" id="19">
  1613. <h1><a class="toc-backref" href="#19">Exports</a></h1>
  1614. <dl class="item">
  1615. <a href="syncio.html#FileMode"><span class="Identifier">FileMode</span></a>
  1616. </dl>
  1617. </div>
  1618. </div>
  1619. </div>
  1620. <div class="twelve-columns footer">
  1621. <span class="nim-sprite"></span>
  1622. <br>
  1623. <small style="color: var(--hint);">Made with Nim. Generated: 2025-04-22 15:32:21 UTC</small>
  1624. </div>
  1625. </div>
  1626. </div>
  1627. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  1628. </body>
  1629. </html>