streams.html 258 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913
  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. </ul>
  256. </div>
  257. <div class="nine columns" id="content">
  258. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  259. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  260. <div id="tocRoot"></div>
  261. <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>
  262. <p>Other modules may provide other implementations for this standard stream interface.</p>
  263. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  264. 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>
  265. <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>
  266. <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>
  267. <ol class="simple"><li>Open input stream</li>
  268. <li>Read or write stream</li>
  269. <li>Close stream</li>
  270. </ol>
  271. <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>
  272. <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
  273. the second line
  274. the third line&quot;&quot;&quot;</span><span class="Punctuation">)</span>
  275. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  276. <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>
  277. <span class="Identifier">echo</span> <span class="Identifier">line</span>
  278. <span class="Comment"># Output:</span>
  279. <span class="Comment"># The first line</span>
  280. <span class="Comment"># the second line</span>
  281. <span class="Comment"># the third line</span>
  282. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  283. <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>
  284. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
  285. <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>
  286. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  287. <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>
  288. <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>
  289. <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>
  290. <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>
  291. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  292. <span class="Comment"># Output (somefile.txt):</span>
  293. <span class="Comment"># The first line</span>
  294. <span class="Comment"># the second line</span>
  295. <span class="Comment"># the third line</span></pre></p>
  296. <p>Read file stream example:</p>
  297. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
  298. <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>
  299. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  300. <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>
  301. <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>
  302. <span class="Identifier">echo</span> <span class="Identifier">line</span>
  303. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  304. <span class="Comment"># Output:</span>
  305. <span class="Comment"># The first line</span>
  306. <span class="Comment"># the second line</span>
  307. <span class="Comment"># the third line</span></pre></p>
  308. <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>
  309. <li><a class="reference external" href="syncio.html">io module</a> for <a class="reference external" href="syncio.html#FileMode">FileMode enum</a></li>
  310. </ul>
  311. </p>
  312. <div class="section" id="6">
  313. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  314. <dl class="item">
  315. <a class="reference external" href="since.html">since</a>, <a class="reference external" href="syncio.html">syncio</a>
  316. </dl>
  317. </div>
  318. <div class="section" id="7">
  319. <h1><a class="toc-backref" href="#7">Types</a></h1>
  320. <dl class="item">
  321. <div id="FileStream">
  322. <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>
  323. <dd>
  324. <p>A stream that encapsulates a <tt class="docutils literal"><span class="pre"><span class="Identifier">File</span></span></tt>.</p>
  325. <p><strong>Note:</strong> Not available for JS backend.</p>
  326. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1325" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  327. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1325" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  328. </dd>
  329. </div>
  330. <div id="FileStreamObj">
  331. <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>
  332. <dd>
  333. <p>A file stream object.</p>
  334. <p><strong>Note:</strong> Not available for JS backend.</p>
  335. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1329" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  336. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1329" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  337. </dd>
  338. </div>
  339. <div id="Stream">
  340. <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>
  341. <dd>
  342. All procedures of this module use this type. Procedures don't directly use <a class="reference external" href="#StreamObj">StreamObj</a>.
  343. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L113" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  344. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L113" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  345. </dd>
  346. </div>
  347. <div id="StreamObj">
  348. <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>
  349. <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>
  350. <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>.}
  351. <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>
  352. <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>
  353. <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>.}
  354. <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>
  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> <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>.}
  356. <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>
  357. <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>.}
  358. <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> {.
  359. <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>.}
  360. <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>
  361. <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>.}
  362. <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>
  363. <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>.}
  364. <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>
  365. <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>.}
  366. <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>
  367. <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>.}
  368. <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>
  369. <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>
  370. <dd>
  371. <p>Stream interface that supports writing or reading.</p>
  372. <p><strong>Note:</strong></p>
  373. <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>
  374. </ul>
  375. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L116" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  376. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L116" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  377. </dd>
  378. </div>
  379. <div id="StringStream">
  380. <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>
  381. <dd>
  382. A stream that encapsulates a string.
  383. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1148" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  384. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1148" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  385. </dd>
  386. </div>
  387. <div id="StringStreamObj">
  388. <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>
  389. <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>
  390. <span class="Comment">## This is updated when called `writeLine` etc.</span></pre></dt>
  391. <dd>
  392. A string stream object.
  393. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1150" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  394. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1150" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  395. </dd>
  396. </div>
  397. </dl>
  398. </div>
  399. <div class="section" id="12">
  400. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  401. <dl class="item">
  402. <div id="atEnd-procs-all">
  403. <div id="atEnd,Stream">
  404. <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>
  405. <dd>
  406. 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.
  407. <p><strong class="examples_text">Example:</strong></p>
  408. <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>
  409. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  410. <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>
  411. <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>
  412. <span class="Keyword">discard</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">true</span>
  414. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  415. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L197" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  416. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L197" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  417. </dd>
  418. </div>
  419. </div>
  420. <div id="close-procs-all">
  421. <div id="close,Stream">
  422. <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>
  423. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  424. <dd>
  425. <p>Closes the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  426. <p>See also:</p>
  427. <ul class="simple"><li><a class="reference external" href="#flush,Stream">flush proc</a></li>
  428. </ul>
  429. <p><strong class="examples_text">Example:</strong></p>
  430. <pre class="listing"><span class="Keyword">block</span><span class="Punctuation">:</span>
  431. <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>
  432. <span class="Comment">## do something...</span>
  433. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  434. <span class="Keyword">block</span><span class="Punctuation">:</span>
  435. <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>
  436. <span class="Comment"># deferring works even if newFileStream fails</span>
  437. <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>
  438. <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>
  439. <span class="Comment">## do something...</span></pre>
  440. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L176" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  441. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L176" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  442. </dd>
  443. </div>
  444. </div>
  445. <div id="flush-procs-all">
  446. <div id="flush,Stream">
  447. <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>
  448. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  449. <dd>
  450. <p>Flushes the buffers that the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> might use.</p>
  451. <p>This procedure causes any unwritten data for that stream to be delivered to the host environment to be written to the file.</p>
  452. <p>See also:</p>
  453. <ul class="simple"><li><a class="reference external" href="#close,Stream">close proc</a></li>
  454. </ul>
  455. <p><strong class="examples_text">Example:</strong></p>
  456. <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>
  457. <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>
  458. <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>
  459. <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>
  460. <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>
  461. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  462. <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>
  463. <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>
  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:helloHELLO&quot;</span>
  466. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  467. <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>
  468. <span class="Identifier">removeFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span></pre>
  469. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L147" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  470. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L147" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  471. </dd>
  472. </div>
  473. </div>
  474. <div id="getPosition-procs-all">
  475. <div id="getPosition,Stream">
  476. <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>
  477. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  478. <dd>
  479. Retrieves the current position in the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
  480. <p><strong class="examples_text">Example:</strong></p>
  481. <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>
  482. <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>
  483. <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>
  484. <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>
  485. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  486. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L223" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  487. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L223" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  488. </dd>
  489. </div>
  490. </div>
  491. <div id="newFileStream-procs-all">
  492. <div id="newFileStream,File">
  493. <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>
  494. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  495. <dd>
  496. <p>Creates a new stream from the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>.</p>
  497. <p><strong>Note:</strong> Not available for JS backend.</p>
  498. <p>See also:</p>
  499. <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
  500. <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>
  501. <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>
  502. </ul>
  503. <p><strong class="examples_text">Example:</strong></p>
  504. <pre class="listing"><span class="Comment">## Input (somefile.txt):</span>
  505. <span class="Comment">## The first line</span>
  506. <span class="Comment">## the second line</span>
  507. <span class="Comment">## the third line</span>
  508. <span class="Keyword">var</span> <span class="Identifier">f</span><span class="Punctuation">:</span> <span class="Identifier">File</span>
  509. <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>
  510. <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>
  511. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  512. <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>
  513. <span class="Identifier">echo</span> <span class="Identifier">line</span>
  514. <span class="Comment">## Output:</span>
  515. <span class="Comment">## The first line</span>
  516. <span class="Comment">## the second line</span>
  517. <span class="Comment">## the third line</span>
  518. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  519. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1362" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  520. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1362" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  521. </dd>
  522. </div>
  523. <div id="newFileStream,string,FileMode,int">
  524. <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>
  525. <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>
  526. <dd>
  527. <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>
  528. <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>
  529. <p><strong>Note:</strong></p>
  530. <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>
  531. <li>Not available for JS backend.</li>
  532. </ul>
  533. <p>See also:</p>
  534. <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
  535. <li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
  536. <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>
  537. </ul>
  538. <p><strong class="examples_text">Example:</strong></p>
  539. <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>
  540. <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>
  541. <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>
  542. <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>
  543. <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>
  544. <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>
  545. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  546. <span class="Comment">## Output (somefile.txt)</span>
  547. <span class="Comment">## The first line</span>
  548. <span class="Comment">## the second line</span>
  549. <span class="Comment">## the third line</span>
  550. <span class="Identifier">removeFile</span><span class="Punctuation">(</span><span class="StringLit">&quot;somefile.txt&quot;</span><span class="Punctuation">)</span></pre>
  551. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1405" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  552. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1405" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  553. </dd>
  554. </div>
  555. </div>
  556. <div id="newStringStream-procs-all">
  557. <div id="newStringStream,sinkstring">
  558. <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>
  559. <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>
  560. <dd>
  561. <p>Creates a new stream from the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  562. <p>See also:</p>
  563. <ul class="simple"><li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
  564. <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>
  565. <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>
  566. </ul>
  567. <p><strong class="examples_text">Example:</strong></p>
  568. <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>
  569. <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>
  570. <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>
  571. <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>
  572. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  573. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1287" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  574. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1287" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  575. </dd>
  576. </div>
  577. </div>
  578. <div id="openFileStream-procs-all">
  579. <div id="openFileStream,string,FileMode,int">
  580. <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>
  581. <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>
  582. <dd>
  583. <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>
  584. <p><strong>Note:</strong> Not available for JS backend.</p>
  585. <p>See also:</p>
  586. <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
  587. <li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
  588. <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>
  589. </ul>
  590. <p><strong class="examples_text">Example:</strong></p>
  591. <pre class="listing"><span class="Keyword">try</span><span class="Punctuation">:</span>
  592. <span class="Comment">## Input (somefile.txt):</span>
  593. <span class="Comment">## The first line</span>
  594. <span class="Comment">## the second line</span>
  595. <span class="Comment">## the third line</span>
  596. <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>
  597. <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>
  598. <span class="Comment">## Output:</span>
  599. <span class="Comment">## The first line</span>
  600. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  601. <span class="Keyword">except</span><span class="Punctuation">:</span>
  602. <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>
  603. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1444" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  604. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1444" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  605. </dd>
  606. </div>
  607. </div>
  608. <div id="peek-procs-all">
  609. <div id="peek,Stream,T">
  610. <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>
  611. <dd>
  612. <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>
  613. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  614. <p><strong class="examples_text">Example:</strong></p>
  615. <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>
  616. <span class="Comment">## peekInt</span>
  617. <span class="Keyword">var</span> <span class="Identifier">i</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
  618. <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>
  619. <span class="Identifier">doAssert</span> <span class="Identifier">i</span> <span class="Operator">==</span> <span class="DecNumber">48</span>
  620. <span class="Comment">## peekData</span>
  621. <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>
  622. <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>
  623. <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>
  624. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  625. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L433" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  626. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L433" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  627. </dd>
  628. </div>
  629. </div>
  630. <div id="peekBool-procs-all">
  631. <div id="peekBool,Stream">
  632. <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>
  633. <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>
  634. <dd>
  635. <p>Peeks a bool from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  636. <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>
  637. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  638. <p><strong class="examples_text">Example:</strong></p>
  639. <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>
  640. <span class="Comment">## setup for reading data</span>
  641. <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>
  642. <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>
  643. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  644. <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>
  645. <span class="Comment">## get data</span>
  646. <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>
  647. <span class="Comment">## not false</span>
  648. <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>
  649. <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>
  650. <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>
  651. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  652. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L517" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  653. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L517" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  654. </dd>
  655. </div>
  656. </div>
  657. <div id="peekChar-procs-all">
  658. <div id="peekChar,Stream">
  659. <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>
  660. <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>
  661. <dd>
  662. 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.
  663. <p><strong class="examples_text">Example:</strong></p>
  664. <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>
  665. <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>
  666. <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>
  667. <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>
  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">'\x00'</span>
  669. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  670. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L473" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  671. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L473" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  672. </dd>
  673. </div>
  674. </div>
  675. <div id="peekData-procs-all">
  676. <div id="peekData,Stream,pointer,int">
  677. <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> {.
  678. <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>
  679. <dd>
  680. <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>
  681. <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>
  682. <p><strong class="examples_text">Example:</strong></p>
  683. <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>
  684. <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>
  685. <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>
  686. <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>
  687. <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>
  688. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  689. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L313" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  690. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L313" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  691. </dd>
  692. </div>
  693. </div>
  694. <div id="peekFloat32-procs-all">
  695. <div id="peekFloat32,Stream">
  696. <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>
  697. <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>
  698. <dd>
  699. <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>
  700. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  701. <p><strong class="examples_text">Example:</strong></p>
  702. <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>
  703. <span class="Comment">## setup for reading data</span>
  704. <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>
  705. <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>
  706. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  707. <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>
  708. <span class="Comment">## get data</span>
  709. <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>
  710. <span class="Comment">## not 2'f32</span>
  711. <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>
  712. <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>
  713. <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>
  714. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  715. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L884" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  716. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L884" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  717. </dd>
  718. </div>
  719. </div>
  720. <div id="peekFloat64-procs-all">
  721. <div id="peekFloat64,Stream">
  722. <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>
  723. <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>
  724. <dd>
  725. <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>
  726. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  727. <p><strong class="examples_text">Example:</strong></p>
  728. <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>
  729. <span class="Comment">## setup for reading data</span>
  730. <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>
  731. <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>
  732. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  733. <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>
  734. <span class="Comment">## get data</span>
  735. <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>
  736. <span class="Comment">## not 2'f64</span>
  737. <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>
  738. <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>
  739. <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>
  740. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  741. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L924" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  742. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L924" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  743. </dd>
  744. </div>
  745. </div>
  746. <div id="peekInt8-procs-all">
  747. <div id="peekInt8,Stream">
  748. <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>
  749. <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>
  750. <dd>
  751. <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>
  752. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  753. <p><strong class="examples_text">Example:</strong></p>
  754. <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>
  755. <span class="Comment">## setup for reading data</span>
  756. <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>
  757. <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>
  758. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  759. <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>
  760. <span class="Comment">## get data</span>
  761. <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>
  762. <span class="Comment">## not 2'i8</span>
  763. <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>
  764. <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>
  765. <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>
  766. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  767. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L563" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  768. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L563" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  769. </dd>
  770. </div>
  771. </div>
  772. <div id="peekInt16-procs-all">
  773. <div id="peekInt16,Stream">
  774. <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>
  775. <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>
  776. <dd>
  777. <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>
  778. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  779. <p><strong class="examples_text">Example:</strong></p>
  780. <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>
  781. <span class="Comment">## setup for reading data</span>
  782. <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>
  783. <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>
  784. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  785. <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>
  786. <span class="Comment">## get data</span>
  787. <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>
  788. <span class="Comment">## not 2'i16</span>
  789. <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>
  790. <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>
  791. <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>
  792. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  793. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L603" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  794. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L603" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  795. </dd>
  796. </div>
  797. </div>
  798. <div id="peekInt32-procs-all">
  799. <div id="peekInt32,Stream">
  800. <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>
  801. <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>
  802. <dd>
  803. <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>
  804. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  805. <p><strong class="examples_text">Example:</strong></p>
  806. <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>
  807. <span class="Comment">## setup for reading data</span>
  808. <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>
  809. <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>
  810. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  811. <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>
  812. <span class="Comment">## get data</span>
  813. <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>
  814. <span class="Comment">## not 2'i32</span>
  815. <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>
  816. <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>
  817. <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>
  818. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  819. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L643" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  820. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L643" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  821. </dd>
  822. </div>
  823. </div>
  824. <div id="peekInt64-procs-all">
  825. <div id="peekInt64,Stream">
  826. <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>
  827. <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>
  828. <dd>
  829. <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>
  830. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  831. <p><strong class="examples_text">Example:</strong></p>
  832. <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>
  833. <span class="Comment">## setup for reading data</span>
  834. <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>
  835. <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>
  836. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  837. <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>
  838. <span class="Comment">## get data</span>
  839. <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>
  840. <span class="Comment">## not 2'i64</span>
  841. <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>
  842. <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>
  843. <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>
  844. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  845. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L683" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  846. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L683" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  847. </dd>
  848. </div>
  849. </div>
  850. <div id="peekLine-procs-all">
  851. <div id="peekLine,Stream">
  852. <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>
  853. <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>
  854. <dd>
  855. <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>
  856. <p><strong>Note:</strong> This is not very efficient.</p>
  857. <p>See also:</p>
  858. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  859. <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  860. <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
  861. </ul>
  862. <p><strong class="examples_text">Example:</strong></p>
  863. <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>
  864. <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>
  865. <span class="Comment">## not &quot;the second line&quot;</span>
  866. <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>
  867. <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>
  868. <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>
  869. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  870. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1106" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  871. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1106" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  872. </dd>
  873. </div>
  874. <div id="peekLine,Stream,string">
  875. <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>
  876. <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>
  877. <dd>
  878. <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>
  879. <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>
  880. <p>See also:</p>
  881. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  882. <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  883. <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
  884. </ul>
  885. <p><strong class="examples_text">Example:</strong></p>
  886. <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>
  887. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  888. <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>
  889. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  890. <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>
  891. <span class="Comment">## not &quot;the second line&quot;</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">readLine</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="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  895. <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>
  896. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;the second line&quot;</span>
  897. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  898. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1045" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  899. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1045" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  900. </dd>
  901. </div>
  902. </div>
  903. <div id="peekStr-procs-all">
  904. <div id="peekStr,Stream,int">
  905. <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>
  906. <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>
  907. <dd>
  908. 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.
  909. <p><strong class="examples_text">Example:</strong></p>
  910. <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>
  911. <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>
  912. <span class="Comment">## not &quot;cd</span>
  913. <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>
  914. <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>
  915. <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>
  916. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  917. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L988" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  918. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L988" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  919. </dd>
  920. </div>
  921. <div id="peekStr,Stream,int,string">
  922. <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> {.
  923. <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>
  924. <dd>
  925. 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.
  926. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L983" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  927. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L983" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  928. </dd>
  929. </div>
  930. </div>
  931. <div id="peekUint8-procs-all">
  932. <div id="peekUint8,Stream">
  933. <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>
  934. <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>
  935. <dd>
  936. <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>
  937. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  938. <p><strong class="examples_text">Example:</strong></p>
  939. <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>
  940. <span class="Comment">## setup for reading data</span>
  941. <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>
  942. <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>
  943. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  944. <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>
  945. <span class="Comment">## get data</span>
  946. <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>
  947. <span class="Comment">## not 2'u8</span>
  948. <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>
  949. <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>
  950. <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>
  951. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  952. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L723" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  953. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L723" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  954. </dd>
  955. </div>
  956. </div>
  957. <div id="peekUint16-procs-all">
  958. <div id="peekUint16,Stream">
  959. <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>
  960. <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>
  961. <dd>
  962. <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>
  963. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  964. <p><strong class="examples_text">Example:</strong></p>
  965. <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>
  966. <span class="Comment">## setup for reading data</span>
  967. <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>
  968. <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>
  969. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  970. <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>
  971. <span class="Comment">## get data</span>
  972. <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>
  973. <span class="Comment">## not 2'u16</span>
  974. <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>
  975. <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>
  976. <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>
  977. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  978. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L763" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  979. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L763" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  980. </dd>
  981. </div>
  982. </div>
  983. <div id="peekUint32-procs-all">
  984. <div id="peekUint32,Stream">
  985. <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>
  986. <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>
  987. <dd>
  988. <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>
  989. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  990. <p><strong class="examples_text">Example:</strong></p>
  991. <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>
  992. <span class="Comment">## setup for reading data</span>
  993. <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>
  994. <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>
  995. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  996. <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>
  997. <span class="Comment">## get data</span>
  998. <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>
  999. <span class="Comment">## not 2'u32</span>
  1000. <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>
  1001. <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>
  1002. <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>
  1003. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1004. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L804" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1005. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L804" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1006. </dd>
  1007. </div>
  1008. </div>
  1009. <div id="peekUint64-procs-all">
  1010. <div id="peekUint64,Stream">
  1011. <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>
  1012. <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>
  1013. <dd>
  1014. <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>
  1015. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
  1016. <p><strong class="examples_text">Example:</strong></p>
  1017. <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>
  1018. <span class="Comment">## setup for reading data</span>
  1019. <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>
  1020. <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>
  1021. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1022. <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>
  1023. <span class="Comment">## get data</span>
  1024. <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>
  1025. <span class="Comment">## not 2'u64</span>
  1026. <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>
  1027. <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>
  1028. <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>
  1029. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1030. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L844" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1031. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L844" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1032. </dd>
  1033. </div>
  1034. </div>
  1035. <div id="read-procs-all">
  1036. <div id="read,Stream,T">
  1037. <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>
  1038. <dd>
  1039. <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>
  1040. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1041. <p><strong class="examples_text">Example:</strong></p>
  1042. <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>
  1043. <span class="Comment">## readInt</span>
  1044. <span class="Keyword">var</span> <span class="Identifier">i</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
  1045. <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>
  1046. <span class="Identifier">doAssert</span> <span class="Identifier">i</span> <span class="Operator">==</span> <span class="DecNumber">48</span>
  1047. <span class="Comment">## readData</span>
  1048. <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>
  1049. <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>
  1050. <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>
  1051. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1052. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L414" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1053. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L414" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1054. </dd>
  1055. </div>
  1056. </div>
  1057. <div id="readAll-procs-all">
  1058. <div id="readAll,Stream">
  1059. <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>
  1060. <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>
  1061. <dd>
  1062. Reads all available data.
  1063. <p><strong class="examples_text">Example:</strong></p>
  1064. <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>
  1065. <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>
  1066. <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>
  1067. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1068. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L280" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1069. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L280" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1070. </dd>
  1071. </div>
  1072. </div>
  1073. <div id="readBool-procs-all">
  1074. <div id="readBool,Stream">
  1075. <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>
  1076. <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>
  1077. <dd>
  1078. <p>Reads a bool from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  1079. <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>
  1080. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1081. <p><strong class="examples_text">Example:</strong></p>
  1082. <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>
  1083. <span class="Comment">## setup for reading data</span>
  1084. <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>
  1085. <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>
  1086. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1087. <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>
  1088. <span class="Comment">## get data</span>
  1089. <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>
  1090. <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>
  1091. <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>
  1092. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1093. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L492" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1094. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L492" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1095. </dd>
  1096. </div>
  1097. </div>
  1098. <div id="readChar-procs-all">
  1099. <div id="readChar,Stream">
  1100. <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>
  1101. <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>
  1102. <dd>
  1103. <p>Reads a char from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  1104. <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>
  1105. <p><strong class="examples_text">Example:</strong></p>
  1106. <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>
  1107. <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>
  1108. <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>
  1109. <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>
  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">'3'</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">'\x00'</span>
  1112. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1113. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L452" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1114. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L452" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1115. </dd>
  1116. </div>
  1117. </div>
  1118. <div id="readData-procs-all">
  1119. <div id="readData,Stream,pointer,int">
  1120. <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> {.
  1121. <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>
  1122. <dd>
  1123. <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>
  1124. <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>
  1125. <p><strong class="examples_text">Example:</strong></p>
  1126. <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>
  1127. <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>
  1128. <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>
  1129. <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>
  1130. <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>
  1131. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1132. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L234" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1133. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L234" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1134. </dd>
  1135. </div>
  1136. </div>
  1137. <div id="readDataStr-procs-all">
  1138. <div id="readDataStr,Stream,string,Slice[int]">
  1139. <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> {.
  1140. <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>
  1141. <dd>
  1142. 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>.
  1143. <p><strong class="examples_text">Example:</strong></p>
  1144. <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>
  1145. <span class="Keyword">var</span> <span class="Identifier">buffer</span> <span class="Operator">=</span> <span class="StringLit">&quot;12345&quot;</span>
  1146. <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>
  1147. <span class="Identifier">doAssert</span> <span class="Identifier">buffer</span> <span class="Operator">==</span> <span class="StringLit">&quot;abcd5&quot;</span>
  1148. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1149. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L249" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1150. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L249" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1151. </dd>
  1152. </div>
  1153. </div>
  1154. <div id="readFloat32-procs-all">
  1155. <div id="readFloat32,Stream">
  1156. <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>
  1157. <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>
  1158. <dd>
  1159. <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>
  1160. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1161. <p><strong class="examples_text">Example:</strong></p>
  1162. <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>
  1163. <span class="Comment">## setup for reading data</span>
  1164. <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>
  1165. <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>
  1166. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1167. <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>
  1168. <span class="Comment">## get data</span>
  1169. <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>
  1170. <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>
  1171. <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>
  1172. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1173. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L865" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1174. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L865" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1175. </dd>
  1176. </div>
  1177. </div>
  1178. <div id="readFloat64-procs-all">
  1179. <div id="readFloat64,Stream">
  1180. <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>
  1181. <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>
  1182. <dd>
  1183. <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>
  1184. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1185. <p><strong class="examples_text">Example:</strong></p>
  1186. <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>
  1187. <span class="Comment">## setup for reading data</span>
  1188. <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>
  1189. <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>
  1190. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1191. <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>
  1192. <span class="Comment">## get data</span>
  1193. <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>
  1194. <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>
  1195. <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>
  1196. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1197. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L905" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1198. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L905" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1199. </dd>
  1200. </div>
  1201. </div>
  1202. <div id="readInt8-procs-all">
  1203. <div id="readInt8,Stream">
  1204. <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>
  1205. <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>
  1206. <dd>
  1207. <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>
  1208. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1209. <p><strong class="examples_text">Example:</strong></p>
  1210. <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>
  1211. <span class="Comment">## setup for reading data</span>
  1212. <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>
  1213. <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>
  1214. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1215. <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>
  1216. <span class="Comment">## get data</span>
  1217. <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>
  1218. <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>
  1219. <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>
  1220. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1221. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L544" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1222. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L544" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1223. </dd>
  1224. </div>
  1225. </div>
  1226. <div id="readInt16-procs-all">
  1227. <div id="readInt16,Stream">
  1228. <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>
  1229. <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>
  1230. <dd>
  1231. <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>
  1232. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1233. <p><strong class="examples_text">Example:</strong></p>
  1234. <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>
  1235. <span class="Comment">## setup for reading data</span>
  1236. <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>
  1237. <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>
  1238. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1239. <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>
  1240. <span class="Comment">## get data</span>
  1241. <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>
  1242. <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>
  1243. <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>
  1244. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1245. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L584" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1246. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L584" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1247. </dd>
  1248. </div>
  1249. </div>
  1250. <div id="readInt32-procs-all">
  1251. <div id="readInt32,Stream">
  1252. <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>
  1253. <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>
  1254. <dd>
  1255. <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>
  1256. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1257. <p><strong class="examples_text">Example:</strong></p>
  1258. <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>
  1259. <span class="Comment">## setup for reading data</span>
  1260. <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>
  1261. <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>
  1262. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1263. <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>
  1264. <span class="Comment">## get data</span>
  1265. <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>
  1266. <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>
  1267. <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>
  1268. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1269. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L624" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1270. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L624" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1271. </dd>
  1272. </div>
  1273. </div>
  1274. <div id="readInt64-procs-all">
  1275. <div id="readInt64,Stream">
  1276. <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>
  1277. <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>
  1278. <dd>
  1279. <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>
  1280. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1281. <p><strong class="examples_text">Example:</strong></p>
  1282. <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>
  1283. <span class="Comment">## setup for reading data</span>
  1284. <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>
  1285. <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>
  1286. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1287. <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>
  1288. <span class="Comment">## get data</span>
  1289. <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>
  1290. <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>
  1291. <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>
  1292. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1293. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L664" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1294. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L664" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1295. </dd>
  1296. </div>
  1297. </div>
  1298. <div id="readLine-procs-all">
  1299. <div id="readLine,Stream">
  1300. <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>
  1301. <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>
  1302. <dd>
  1303. <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>
  1304. <p><strong>Note:</strong> This is not very efficient.</p>
  1305. <p>See also:</p>
  1306. <ul class="simple"><li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  1307. <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
  1308. <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
  1309. </ul>
  1310. <p><strong class="examples_text">Example:</strong></p>
  1311. <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>
  1312. <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>
  1313. <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>
  1314. <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>
  1315. <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>
  1316. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1317. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1076" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1318. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1076" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1319. </dd>
  1320. </div>
  1321. <div id="readLine,Stream,string">
  1322. <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>
  1323. <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>
  1324. <dd>
  1325. <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>
  1326. <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>
  1327. <p>See also:</p>
  1328. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  1329. <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
  1330. <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
  1331. </ul>
  1332. <p><strong class="examples_text">Example:</strong></p>
  1333. <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>
  1334. <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  1335. <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>
  1336. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;The first line&quot;</span>
  1337. <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>
  1338. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;the second line&quot;</span>
  1339. <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>
  1340. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;the third line&quot;</span>
  1341. <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>
  1342. <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">&quot;&quot;</span>
  1343. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1344. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1002" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1345. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1002" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1346. </dd>
  1347. </div>
  1348. </div>
  1349. <div id="readStr-procs-all">
  1350. <div id="readStr,Stream,int">
  1351. <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>
  1352. <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>
  1353. <dd>
  1354. 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.
  1355. <p><strong class="examples_text">Example:</strong></p>
  1356. <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>
  1357. <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>
  1358. <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>
  1359. <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>
  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;&quot;</span>
  1361. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1362. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L962" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1363. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L962" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1364. </dd>
  1365. </div>
  1366. <div id="readStr,Stream,int,string">
  1367. <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> {.
  1368. <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>
  1369. <dd>
  1370. 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.
  1371. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L957" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1372. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L957" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1373. </dd>
  1374. </div>
  1375. </div>
  1376. <div id="readUint8-procs-all">
  1377. <div id="readUint8,Stream">
  1378. <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>
  1379. <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>
  1380. <dd>
  1381. <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>
  1382. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1383. <p><strong class="examples_text">Example:</strong></p>
  1384. <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>
  1385. <span class="Comment">## setup for reading data</span>
  1386. <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>
  1387. <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>
  1388. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1389. <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>
  1390. <span class="Comment">## get data</span>
  1391. <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>
  1392. <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>
  1393. <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>
  1394. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1395. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L704" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1396. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L704" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1397. </dd>
  1398. </div>
  1399. </div>
  1400. <div id="readUint16-procs-all">
  1401. <div id="readUint16,Stream">
  1402. <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>
  1403. <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>
  1404. <dd>
  1405. <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>
  1406. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1407. <p><strong class="examples_text">Example:</strong></p>
  1408. <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>
  1409. <span class="Comment">## setup for reading data</span>
  1410. <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>
  1411. <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>
  1412. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1413. <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>
  1414. <span class="Comment">## get data</span>
  1415. <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>
  1416. <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>
  1417. <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>
  1418. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1419. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L744" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1420. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L744" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1421. </dd>
  1422. </div>
  1423. </div>
  1424. <div id="readUint32-procs-all">
  1425. <div id="readUint32,Stream">
  1426. <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>
  1427. <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>
  1428. <dd>
  1429. <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>
  1430. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1431. <p><strong class="examples_text">Example:</strong></p>
  1432. <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>
  1433. <span class="Comment">## setup for reading data</span>
  1434. <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>
  1435. <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>
  1436. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1437. <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>
  1438. <span class="Comment">## get data</span>
  1439. <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>
  1440. <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>
  1441. <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>
  1442. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1443. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L784" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1444. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L784" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1445. </dd>
  1446. </div>
  1447. </div>
  1448. <div id="readUint64-procs-all">
  1449. <div id="readUint64,Stream">
  1450. <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>
  1451. <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>
  1452. <dd>
  1453. <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>
  1454. <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
  1455. <p><strong class="examples_text">Example:</strong></p>
  1456. <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>
  1457. <span class="Comment">## setup for reading data</span>
  1458. <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>
  1459. <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>
  1460. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1461. <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>
  1462. <span class="Comment">## get data</span>
  1463. <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>
  1464. <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>
  1465. <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>
  1466. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1467. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L825" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1468. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L825" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1469. </dd>
  1470. </div>
  1471. </div>
  1472. <div id="setPosition-procs-all">
  1473. <div id="setPosition,Stream,int">
  1474. <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>
  1475. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1476. <dd>
  1477. 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>.
  1478. <p><strong class="examples_text">Example:</strong></p>
  1479. <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>
  1480. <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>
  1481. <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>
  1482. <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>
  1483. <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>
  1484. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1485. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L211" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1486. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L211" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1487. </dd>
  1488. </div>
  1489. </div>
  1490. <div id="write-procs-all">
  1491. <div id="write,Stream,varargs[string,]">
  1492. <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>
  1493. <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>
  1494. <dd>
  1495. Writes one or more strings to the the stream. No length fields or terminating zeros are written.
  1496. <p><strong class="examples_text">Example:</strong></p>
  1497. <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>
  1498. <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>
  1499. <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>
  1500. <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>
  1501. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1502. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L388" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1503. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L388" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1504. </dd>
  1505. </div>
  1506. <div id="write,Stream,string">
  1507. <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>
  1508. <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>
  1509. <dd>
  1510. 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.
  1511. <p><strong class="examples_text">Example:</strong></p>
  1512. <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>
  1513. <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>
  1514. <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>
  1515. <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>
  1516. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1517. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L368" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1518. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L368" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1519. </dd>
  1520. </div>
  1521. <div id="write,Stream,T">
  1522. <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>
  1523. <dd>
  1524. <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>
  1525. <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>
  1526. <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>
  1527. <p><strong class="examples_text">Example:</strong></p>
  1528. <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>
  1529. <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>
  1530. <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>
  1531. <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>
  1532. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1533. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L350" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1534. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L350" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1535. </dd>
  1536. </div>
  1537. </div>
  1538. <div id="writeData-procs-all">
  1539. <div id="writeData,Stream,pointer,int">
  1540. <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> {.
  1541. <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>
  1542. <dd>
  1543. <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>
  1544. <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>
  1545. <p><strong class="examples_text">Example:</strong></p>
  1546. <pre class="listing"><span class="Comment">## writeData</span>
  1547. <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>
  1548. <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>
  1549. <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>
  1550. <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>
  1551. <span class="Comment">## readData</span>
  1552. <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>
  1553. <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>
  1554. <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>
  1555. <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>
  1556. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1557. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L329" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1558. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L329" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1559. </dd>
  1560. </div>
  1561. </div>
  1562. <div id="writeLine-procs-all">
  1563. <div id="writeLine,Stream,varargs[string,]">
  1564. <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> {.
  1565. <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>
  1566. <dd>
  1567. 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.
  1568. <p><strong class="examples_text">Example:</strong></p>
  1569. <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>
  1570. <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>
  1571. <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>
  1572. <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>
  1573. <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>
  1574. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1575. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L400" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1576. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L400" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1577. </dd>
  1578. </div>
  1579. </div>
  1580. </dl>
  1581. </div>
  1582. <div class="section" id="15">
  1583. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  1584. <dl class="item">
  1585. <div id="lines-iterators-all">
  1586. <div id="lines.i,Stream">
  1587. <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>
  1588. <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>
  1589. <dd>
  1590. <p>Iterates over every line in the stream. The iteration is based on <tt class="docutils literal"><span class="pre">readLine</span></tt>.</p>
  1591. <p>See also:</p>
  1592. <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
  1593. <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
  1594. </ul>
  1595. <p><strong class="examples_text">Example:</strong></p>
  1596. <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>
  1597. <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>
  1598. <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>
  1599. <span class="Identifier">lines</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">line</span>
  1600. <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>
  1601. <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  1602. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1128" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1603. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1128" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1604. </dd>
  1605. </div>
  1606. </div>
  1607. </dl>
  1608. </div>
  1609. </div>
  1610. </div>
  1611. <div class="twelve-columns footer">
  1612. <span class="nim-sprite"></span>
  1613. <br>
  1614. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:28:03 UTC</small>
  1615. </div>
  1616. </div>
  1617. </div>
  1618. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  1619. </body>
  1620. </html>