12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/streams</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <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=="/>
- <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=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/streams</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li><a class="reference" id="basic-usage_toc" href="#basic-usage">Basic usage</a></li>
- <ul class="simple"><li><a class="reference" id="basic-usage-stringstream-example_toc" href="#basic-usage-stringstream-example">StringStream example</a></li>
- <li><a class="reference" id="basic-usage-filestream-example_toc" href="#basic-usage-filestream-example">FileStream example</a></li>
- </ul><li><a class="reference" id="see-also_toc" href="#see-also">See also</a></li>
- <li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#FileStream" title="FileStream = ref FileStreamObj">FileStream</a></li>
- <li><a class="reference" href="#FileStreamObj" title="FileStreamObj = object of Stream">FileStreamObj</a></li>
- <li><a class="reference" href="#Stream" title="Stream = ref StreamObj">Stream</a></li>
- <li><a class="reference" href="#StreamObj" title="StreamObj = object of RootObj
- closeImpl*: proc (s: Stream) {.nimcall, raises: [IOError, OSError],
- tags: [WriteIOEffect], gcsafe.}
- atEndImpl*: proc (s: Stream): bool {.nimcall,
- raises: [Defect, IOError, OSError],
- tags: [], gcsafe.}
- setPositionImpl*: proc (s: Stream; pos: int) {.nimcall,
- raises: [Defect, IOError, OSError], tags: [], gcsafe.}
- getPositionImpl*: proc (s: Stream): int {.nimcall,
- raises: [Defect, IOError, OSError], tags: [], gcsafe.}
- readDataStrImpl*: proc (s: Stream; buffer: var string; slice: Slice[int]): int {.
- nimcall, raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
- readLineImpl*: proc (s: Stream; line: var string): bool {.nimcall,
- raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
- readDataImpl*: proc (s: Stream; buffer: pointer; bufLen: int): int {.nimcall,
- raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
- peekDataImpl*: proc (s: Stream; buffer: pointer; bufLen: int): int {.nimcall,
- raises: [Defect, IOError, OSError], tags: [ReadIOEffect], gcsafe.}
- writeDataImpl*: proc (s: Stream; buffer: pointer; bufLen: int) {.nimcall,
- raises: [Defect, IOError, OSError], tags: [WriteIOEffect], gcsafe.}
- flushImpl*: proc (s: Stream) {.nimcall, raises: [Defect, IOError, OSError],
- tags: [WriteIOEffect], gcsafe.}">StreamObj</a></li>
- <li><a class="reference" href="#StringStream" title="StringStream = ref StringStreamObj">StringStream</a></li>
- <li><a class="reference" href="#StringStreamObj" title="StringStreamObj = object of StreamObj
- data*: string ## A string data.
- ## This is updated when called `writeLine` etc.">StringStreamObj</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">atEnd
- <li><a class="reference" href="#atEnd%2CStream" title="atEnd(s: Stream): bool">atEnd(s: Stream): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">close
- <li><a class="reference" href="#close%2CStream" title="close(s: Stream)">close(s: Stream)</a></li>
- </ul>
- <ul class="simple nested-toc-section">flush
- <li><a class="reference" href="#flush%2CStream" title="flush(s: Stream)">flush(s: Stream)</a></li>
- </ul>
- <ul class="simple nested-toc-section">getPosition
- <li><a class="reference" href="#getPosition%2CStream" title="getPosition(s: Stream): int">getPosition(s: Stream): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">newFileStream
- <li><a class="reference" href="#newFileStream%2CFile" title="newFileStream(f: File): owned FileStream">newFileStream(f: File): owned FileStream</a></li>
- <li><a class="reference" href="#newFileStream%2Cstring%2CFileMode%2Cint" title="newFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
- FileStream">newFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
- FileStream</a></li>
- </ul>
- <ul class="simple nested-toc-section">newStringStream
- <li><a class="reference" href="#newStringStream%2Csinkstring" title="newStringStream(s: sink string = ""): owned StringStream">newStringStream(s: sink string = ""): owned StringStream</a></li>
- </ul>
- <ul class="simple nested-toc-section">openFileStream
- <li><a class="reference" href="#openFileStream%2Cstring%2CFileMode%2Cint" title="openFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
- FileStream">openFileStream(filename: string; mode: FileMode = fmRead; bufSize: int = -1): owned
- FileStream</a></li>
- </ul>
- <ul class="simple nested-toc-section">peek
- <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>
- </ul>
- <ul class="simple nested-toc-section">peekBool
- <li><a class="reference" href="#peekBool%2CStream" title="peekBool(s: Stream): bool">peekBool(s: Stream): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekChar
- <li><a class="reference" href="#peekChar%2CStream" title="peekChar(s: Stream): char">peekChar(s: Stream): char</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekData
- <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>
- </ul>
- <ul class="simple nested-toc-section">peekFloat32
- <li><a class="reference" href="#peekFloat32%2CStream" title="peekFloat32(s: Stream): float32">peekFloat32(s: Stream): float32</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekFloat64
- <li><a class="reference" href="#peekFloat64%2CStream" title="peekFloat64(s: Stream): float64">peekFloat64(s: Stream): float64</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekInt8
- <li><a class="reference" href="#peekInt8%2CStream" title="peekInt8(s: Stream): int8">peekInt8(s: Stream): int8</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekInt16
- <li><a class="reference" href="#peekInt16%2CStream" title="peekInt16(s: Stream): int16">peekInt16(s: Stream): int16</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekInt32
- <li><a class="reference" href="#peekInt32%2CStream" title="peekInt32(s: Stream): int32">peekInt32(s: Stream): int32</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekInt64
- <li><a class="reference" href="#peekInt64%2CStream" title="peekInt64(s: Stream): int64">peekInt64(s: Stream): int64</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekLine
- <li><a class="reference" href="#peekLine%2CStream" title="peekLine(s: Stream): string">peekLine(s: Stream): string</a></li>
- <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>
- </ul>
- <ul class="simple nested-toc-section">peekStr
- <li><a class="reference" href="#peekStr%2CStream%2Cint" title="peekStr(s: Stream; length: int): string">peekStr(s: Stream; length: int): string</a></li>
- <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>
- </ul>
- <ul class="simple nested-toc-section">peekUint8
- <li><a class="reference" href="#peekUint8%2CStream" title="peekUint8(s: Stream): uint8">peekUint8(s: Stream): uint8</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekUint16
- <li><a class="reference" href="#peekUint16%2CStream" title="peekUint16(s: Stream): uint16">peekUint16(s: Stream): uint16</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekUint32
- <li><a class="reference" href="#peekUint32%2CStream" title="peekUint32(s: Stream): uint32">peekUint32(s: Stream): uint32</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekUint64
- <li><a class="reference" href="#peekUint64%2CStream" title="peekUint64(s: Stream): uint64">peekUint64(s: Stream): uint64</a></li>
- </ul>
- <ul class="simple nested-toc-section">read
- <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>
- </ul>
- <ul class="simple nested-toc-section">readAll
- <li><a class="reference" href="#readAll%2CStream" title="readAll(s: Stream): string">readAll(s: Stream): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">readBool
- <li><a class="reference" href="#readBool%2CStream" title="readBool(s: Stream): bool">readBool(s: Stream): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">readChar
- <li><a class="reference" href="#readChar%2CStream" title="readChar(s: Stream): char">readChar(s: Stream): char</a></li>
- </ul>
- <ul class="simple nested-toc-section">readData
- <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>
- </ul>
- <ul class="simple nested-toc-section">readDataStr
- <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>
- </ul>
- <ul class="simple nested-toc-section">readFloat32
- <li><a class="reference" href="#readFloat32%2CStream" title="readFloat32(s: Stream): float32">readFloat32(s: Stream): float32</a></li>
- </ul>
- <ul class="simple nested-toc-section">readFloat64
- <li><a class="reference" href="#readFloat64%2CStream" title="readFloat64(s: Stream): float64">readFloat64(s: Stream): float64</a></li>
- </ul>
- <ul class="simple nested-toc-section">readInt8
- <li><a class="reference" href="#readInt8%2CStream" title="readInt8(s: Stream): int8">readInt8(s: Stream): int8</a></li>
- </ul>
- <ul class="simple nested-toc-section">readInt16
- <li><a class="reference" href="#readInt16%2CStream" title="readInt16(s: Stream): int16">readInt16(s: Stream): int16</a></li>
- </ul>
- <ul class="simple nested-toc-section">readInt32
- <li><a class="reference" href="#readInt32%2CStream" title="readInt32(s: Stream): int32">readInt32(s: Stream): int32</a></li>
- </ul>
- <ul class="simple nested-toc-section">readInt64
- <li><a class="reference" href="#readInt64%2CStream" title="readInt64(s: Stream): int64">readInt64(s: Stream): int64</a></li>
- </ul>
- <ul class="simple nested-toc-section">readLine
- <li><a class="reference" href="#readLine%2CStream" title="readLine(s: Stream): string">readLine(s: Stream): string</a></li>
- <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>
- </ul>
- <ul class="simple nested-toc-section">readStr
- <li><a class="reference" href="#readStr%2CStream%2Cint" title="readStr(s: Stream; length: int): string">readStr(s: Stream; length: int): string</a></li>
- <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>
- </ul>
- <ul class="simple nested-toc-section">readUint8
- <li><a class="reference" href="#readUint8%2CStream" title="readUint8(s: Stream): uint8">readUint8(s: Stream): uint8</a></li>
- </ul>
- <ul class="simple nested-toc-section">readUint16
- <li><a class="reference" href="#readUint16%2CStream" title="readUint16(s: Stream): uint16">readUint16(s: Stream): uint16</a></li>
- </ul>
- <ul class="simple nested-toc-section">readUint32
- <li><a class="reference" href="#readUint32%2CStream" title="readUint32(s: Stream): uint32">readUint32(s: Stream): uint32</a></li>
- </ul>
- <ul class="simple nested-toc-section">readUint64
- <li><a class="reference" href="#readUint64%2CStream" title="readUint64(s: Stream): uint64">readUint64(s: Stream): uint64</a></li>
- </ul>
- <ul class="simple nested-toc-section">setPosition
- <li><a class="reference" href="#setPosition%2CStream%2Cint" title="setPosition(s: Stream; pos: int)">setPosition(s: Stream; pos: int)</a></li>
- </ul>
- <ul class="simple nested-toc-section">write
- <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>
- <li><a class="reference" href="#write%2CStream%2Cstring" title="write(s: Stream; x: string)">write(s: Stream; x: string)</a></li>
- <li><a class="reference" href="#write%2CStream%2CT" title="write[T](s: Stream; x: T)">write[T](s: Stream; x: T)</a></li>
- </ul>
- <ul class="simple nested-toc-section">writeData
- <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>
- </ul>
- <ul class="simple nested-toc-section">writeLine
- <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>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">lines
- <li><a class="reference" href="#lines.i%2CStream" title="lines(s: Stream): string">lines(s: Stream): string</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <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>
- <p>Other modules may provide other implementations for this standard stream interface.</p>
- <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
- 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>
- <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>
- <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>
- <ol class="simple"><li>Open input stream</li>
- <li>Read or write stream</li>
- <li>Close stream</li>
- </ol>
- <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>
- <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">"""The first line
- the second line
- the third line"""</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <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>
- <span class="Identifier">echo</span> <span class="Identifier">line</span>
- <span class="Comment"># Output:</span>
- <span class="Comment"># The first line</span>
- <span class="Comment"># the second line</span>
- <span class="Comment"># the third line</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
- <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>
- <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
- <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">"somefile.txt"</span><span class="Punctuation">,</span> <span class="Identifier">fmWrite</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">"The first line"</span><span class="Punctuation">)</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">"the second line"</span><span class="Punctuation">)</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">"the third line"</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>
- <span class="Comment"># Output (somefile.txt):</span>
- <span class="Comment"># The first line</span>
- <span class="Comment"># the second line</span>
- <span class="Comment"># the third line</span></pre></p>
- <p>Read file stream example:</p>
- <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
- <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">"somefile.txt"</span><span class="Punctuation">,</span> <span class="Identifier">fmRead</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <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>
- <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>
- <span class="Identifier">echo</span> <span class="Identifier">line</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Comment"># Output:</span>
- <span class="Comment"># The first line</span>
- <span class="Comment"># the second line</span>
- <span class="Comment"># the third line</span></pre></p>
- <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>
- <li><a class="reference external" href="syncio.html">io module</a> for <a class="reference external" href="syncio.html#FileMode">FileMode enum</a></li>
- </ul>
- </p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="since.html">since</a>, <a class="reference external" href="syncio.html">syncio</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="FileStream">
- <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>
- <dd>
-
- <p>A stream that encapsulates a <tt class="docutils literal"><span class="pre"><span class="Identifier">File</span></span></tt>.</p>
- <p><strong>Note:</strong> Not available for JS backend.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1325" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1325" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="FileStreamObj">
- <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>
- <dd>
-
- <p>A file stream object.</p>
- <p><strong>Note:</strong> Not available for JS backend.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1329" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1329" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="Stream">
- <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>
- <dd>
-
- All procedures of this module use this type. Procedures don't directly use <a class="reference external" href="#StreamObj">StreamObj</a>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L113" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L113" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="StreamObj">
- <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>
- <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>
- <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>.}
- <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>
- <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>.}
- <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>
- <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>.}
- <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>
- <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>.}
- <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> {.
- <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>.}
- <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>
- <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>.}
- <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>
- <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>.}
- <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>
- <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>.}
- <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>
- <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>.}
- <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>
- <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>
- <dd>
-
- <p>Stream interface that supports writing or reading.</p>
- <p><strong>Note:</strong></p>
- <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>
- </ul>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L116" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L116" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="StringStream">
- <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>
- <dd>
-
- A stream that encapsulates a string.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1148" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1148" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="StringStreamObj">
- <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>
- <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>
- <span class="Comment">## This is updated when called `writeLine` etc.</span></pre></dt>
- <dd>
-
- A string stream object.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1150" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1150" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="atEnd-procs-all">
- <div id="atEnd,Stream">
- <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>
- <dd>
-
- 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <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>
- <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>
- <span class="Keyword">discard</span>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L197" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L197" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="close-procs-all">
- <div id="close,Stream">
- <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>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Closes the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#flush,Stream">flush proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">block</span><span class="Punctuation">:</span>
- <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">"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"</span><span class="Punctuation">)</span>
- <span class="Comment">## do something...</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">block</span><span class="Punctuation">:</span>
- <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">"amissingfile.txt"</span><span class="Punctuation">)</span>
- <span class="Comment"># deferring works even if newFileStream fails</span>
- <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>
- <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>
- <span class="Comment">## do something...</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L176" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L176" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="flush-procs-all">
- <div id="flush,Stream">
- <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>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Flushes the buffers that the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> might use.</p>
- <p>This procedure causes any unwritten data for that stream to be delivered to the host environment to be written to the file.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#close,Stream">close proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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">"somefile.txt"</span><span class="Punctuation">,</span> <span class="Identifier">fmWrite</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"Before write:"</span> <span class="Operator">&</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">"somefile.txt"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"Before write:"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">"hello"</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"After write:"</span> <span class="Operator">&</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">"somefile.txt"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"After write:"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"After flush:"</span> <span class="Operator">&</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">"somefile.txt"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"After flush:hello"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">"HELLO"</span><span class="Punctuation">)</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"After flush:"</span> <span class="Operator">&</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">"somefile.txt"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"After flush:helloHELLO"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="StringLit">"After close:"</span> <span class="Operator">&</span> <span class="Identifier">readFile</span><span class="Punctuation">(</span><span class="StringLit">"somefile.txt"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"After close:helloHELLO"</span>
- <span class="Identifier">removeFile</span><span class="Punctuation">(</span><span class="StringLit">"somefile.txt"</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L147" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L147" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="getPosition-procs-all">
- <div id="getPosition,Stream">
- <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>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Retrieves the current position in the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L223" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L223" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="newFileStream-procs-all">
- <div id="newFileStream,File">
- <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>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Creates a new stream from the file <tt class="docutils literal"><span class="pre"><span class="Identifier">f</span></span></tt>.</p>
- <p><strong>Note:</strong> Not available for JS backend.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
- <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>
- <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>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Comment">## Input (somefile.txt):</span>
- <span class="Comment">## The first line</span>
- <span class="Comment">## the second line</span>
- <span class="Comment">## the third line</span>
- <span class="Keyword">var</span> <span class="Identifier">f</span><span class="Punctuation">:</span> <span class="Identifier">File</span>
- <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">"somefile.txt"</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>
- <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>
- <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <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>
- <span class="Identifier">echo</span> <span class="Identifier">line</span>
- <span class="Comment">## Output:</span>
- <span class="Comment">## The first line</span>
- <span class="Comment">## the second line</span>
- <span class="Comment">## the third line</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1362" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1362" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="newFileStream,string,FileMode,int">
- <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>
- <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>
- <dd>
-
- <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>
- <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>
- <p><strong>Note:</strong></p>
- <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>
- <li>Not available for JS backend.</li>
- </ul>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
- <li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
- <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>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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">"somefile.txt"</span><span class="Punctuation">,</span> <span class="Identifier">fmWrite</span><span class="Punctuation">)</span>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">"The first line"</span><span class="Punctuation">)</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">"the second line"</span><span class="Punctuation">)</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="StringLit">"the third line"</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>
- <span class="Comment">## Output (somefile.txt)</span>
- <span class="Comment">## The first line</span>
- <span class="Comment">## the second line</span>
- <span class="Comment">## the third line</span>
- <span class="Identifier">removeFile</span><span class="Punctuation">(</span><span class="StringLit">"somefile.txt"</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1405" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1405" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="newStringStream-procs-all">
- <div id="newStringStream,sinkstring">
- <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">""</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>
- <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>
- <dd>
-
- <p>Creates a new stream from the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
- <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>
- <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>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <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">"The first line"</span>
- <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">"the second line"</span>
- <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">"the third line"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1287" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1287" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="openFileStream-procs-all">
- <div id="openFileStream,string,FileMode,int">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#newStringStream,string">newStringStream proc</a> creates a new stream from string.</li>
- <li><a class="reference external" href="#newFileStream,File">newFileStream proc</a> creates a file stream from opened File.</li>
- <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>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">try</span><span class="Punctuation">:</span>
- <span class="Comment">## Input (somefile.txt):</span>
- <span class="Comment">## The first line</span>
- <span class="Comment">## the second line</span>
- <span class="Comment">## the third line</span>
- <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">"somefile.txt"</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## Output:</span>
- <span class="Comment">## The first line</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">except</span><span class="Punctuation">:</span>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1444" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1444" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peek-procs-all">
- <div id="peek,Stream,T">
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"012"</span><span class="Punctuation">)</span>
- <span class="Comment">## peekInt</span>
- <span class="Keyword">var</span> <span class="Identifier">i</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">i</span> <span class="Operator">==</span> <span class="DecNumber">48</span>
- <span class="Comment">## peekData</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L433" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L433" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekBool-procs-all">
- <div id="peekBool,Stream">
- <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>
- <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>
- <dd>
-
- <p>Peeks a bool from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not false</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L517" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L517" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekChar-procs-all">
- <div id="peekChar,Stream">
- <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>
- <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>
- <dd>
-
- 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"12</span><span class="EscapeSequence">\n</span><span class="StringLit">3"</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L473" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L473" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekData-procs-all">
- <div id="peekData,Stream,pointer,int">
- <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> {.
- <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>
- <dd>
-
- <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>
- <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..<bufLen</span></tt>.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"abcde"</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L313" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L313" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekFloat32-procs-all">
- <div id="peekFloat32,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'f32</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L884" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L884" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekFloat64-procs-all">
- <div id="peekFloat64,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'f64</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L924" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L924" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekInt8-procs-all">
- <div id="peekInt8,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'i8</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L563" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L563" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekInt16-procs-all">
- <div id="peekInt16,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'i16</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L603" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L603" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekInt32-procs-all">
- <div id="peekInt32,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'i32</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L643" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L643" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekInt64-procs-all">
- <div id="peekInt64,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'i64</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L683" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L683" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekLine-procs-all">
- <div id="peekLine,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> This is not very efficient.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
- <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
- <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <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">"The first line"</span>
- <span class="Comment">## not "the second line"</span>
- <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">"The first line"</span>
- <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">"The first line"</span>
- <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">"the second line"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1106" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1106" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="peekLine,Stream,string">
- <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>
- <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>
- <dd>
-
- <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>
- <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>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
- <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
- <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">"The first line"</span>
- <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>
- <span class="Comment">## not "the second line"</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">"The first line"</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">"The first line"</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">"the second line"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1045" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1045" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekStr-procs-all">
- <div id="peekStr,Stream,int">
- <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>
- <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>
- <dd>
-
- 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"abcde"</span><span class="Punctuation">)</span>
- <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">"ab"</span>
- <span class="Comment">## not "cd</span>
- <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">"ab"</span>
- <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">"ab"</span>
- <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">"cd"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L988" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L988" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="peekStr,Stream,int,string">
- <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> {.
- <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>
- <dd>
-
- 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.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L983" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L983" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekUint8-procs-all">
- <div id="peekUint8,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'u8</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L723" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L723" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekUint16-procs-all">
- <div id="peekUint16,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'u16</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L763" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L763" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekUint32-procs-all">
- <div id="peekUint32,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'u32</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L804" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L804" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekUint64-procs-all">
- <div id="peekUint64,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#peekStr,Stream,int">peekStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <span class="Comment">## not 2'u64</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L844" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L844" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="read-procs-all">
- <div id="read,Stream,T">
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"012"</span><span class="Punctuation">)</span>
- <span class="Comment">## readInt</span>
- <span class="Keyword">var</span> <span class="Identifier">i</span><span class="Punctuation">:</span> <span class="Identifier">int8</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">i</span> <span class="Operator">==</span> <span class="DecNumber">48</span>
- <span class="Comment">## readData</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L414" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L414" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readAll-procs-all">
- <div id="readAll,Stream">
- <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>
- <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>
- <dd>
-
- Reads all available data.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <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">"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"</span>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L280" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L280" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readBool-procs-all">
- <div id="readBool,Stream">
- <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>
- <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>
- <dd>
-
- <p>Reads a bool from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L492" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L492" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readChar-procs-all">
- <div id="readChar,Stream">
- <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>
- <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>
- <dd>
-
- <p>Reads a char from the stream <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
- <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>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"12</span><span class="EscapeSequence">\n</span><span class="StringLit">3"</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L452" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L452" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readData-procs-all">
- <div id="readData,Stream,pointer,int">
- <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> {.
- <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>
- <dd>
-
- <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>
- <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..<bufLen</span></tt>.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"abcde"</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L234" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L234" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readDataStr-procs-all">
- <div id="readDataStr,Stream,string,Slice[int]">
- <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> {.
- <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>
- <dd>
-
- 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>.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"abcde"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">buffer</span> <span class="Operator">=</span> <span class="StringLit">"12345"</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">buffer</span> <span class="Operator">==</span> <span class="StringLit">"abcd5"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L249" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L249" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readFloat32-procs-all">
- <div id="readFloat32,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L865" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L865" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readFloat64-procs-all">
- <div id="readFloat64,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L905" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L905" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readInt8-procs-all">
- <div id="readInt8,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L544" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L544" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readInt16-procs-all">
- <div id="readInt16,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L584" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L584" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readInt32-procs-all">
- <div id="readInt32,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L624" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L624" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readInt64-procs-all">
- <div id="readInt64,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L664" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L664" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readLine-procs-all">
- <div id="readLine,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> This is not very efficient.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
- <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
- <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <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">"The first line"</span>
- <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">"the second line"</span>
- <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">"the third line"</span>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1076" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1076" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="readLine,Stream,string">
- <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>
- <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>
- <dd>
-
- <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>
- <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>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
- <li><a class="reference external" href="#peekLine,Stream">peekLine(Stream) proc</a></li>
- <li><a class="reference external" href="#peekLine,Stream,string">peekLine(Stream, string) proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <span class="Keyword">var</span> <span class="Identifier">line</span> <span class="Operator">=</span> <span class="StringLit">""</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">"The first line"</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">"the second line"</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">"the third line"</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">line</span> <span class="Operator">==</span> <span class="StringLit">""</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1002" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1002" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readStr-procs-all">
- <div id="readStr,Stream,int">
- <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>
- <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>
- <dd>
-
- 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"abcde"</span><span class="Punctuation">)</span>
- <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">"ab"</span>
- <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">"cd"</span>
- <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">"e"</span>
- <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">""</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L962" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L962" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="readStr,Stream,int,string">
- <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> {.
- <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>
- <dd>
-
- 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.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L957" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L957" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readUint8-procs-all">
- <div id="readUint8,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L704" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L704" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readUint16-procs-all">
- <div id="readUint16,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L744" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L744" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readUint32-procs-all">
- <div id="readUint32,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L784" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L784" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="readUint64-procs-all">
- <div id="readUint64,Stream">
- <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>
- <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>
- <dd>
-
- <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>
- <p><strong>Note:</strong> Not available for JS backend. Use <a class="reference external" href="#readStr,Stream,int">readStr</a> for now.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Comment">## setup for reading data</span>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">flush</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <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>
- <span class="Comment">## get data</span>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L825" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L825" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="setPosition-procs-all">
- <div id="setPosition,Stream,int">
- <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>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- 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>.
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <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>
- <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">"first line"</span>
- <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>
- <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">"The first line"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L211" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L211" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="write-procs-all">
- <div id="write,Stream,varargs[string,]">
- <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>
- <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>
- <dd>
-
- Writes one or more strings to the the stream. No length fields or terminating zeros are written.
- <p><strong class="examples_text">Example:</strong></p>
- <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">""</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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">"1234"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L388" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L388" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="write,Stream,string">
- <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>
- <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>
- <dd>
-
- 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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">""</span><span class="Punctuation">)</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">"THE FIRST LINE"</span><span class="Punctuation">)</span>
- <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>
- <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">"THE FIRST LINE"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L368" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L368" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="write,Stream,T">
- <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>
- <dd>
-
- <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>
- <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>
- <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>
- <p><strong class="examples_text">Example:</strong></p>
- <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">""</span><span class="Punctuation">)</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">write</span><span class="Punctuation">(</span><span class="StringLit">"abcde"</span><span class="Punctuation">)</span>
- <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>
- <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">"abcde"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L350" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L350" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="writeData-procs-all">
- <div id="writeData,Stream,pointer,int">
- <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> {.
- <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>
- <dd>
-
- <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>
- <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..<bufLen</span></tt>.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Comment">## writeData</span>
- <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">""</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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>
- <span class="Comment">## readData</span>
- <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>
- <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>
- <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>
- <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>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L329" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L329" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="writeLine-procs-all">
- <div id="writeLine,Stream,varargs[string,]">
- <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> {.
- <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>
- <dd>
-
- 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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">""</span><span class="Punctuation">)</span>
- <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>
- <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>
- <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>
- <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">"12</span><span class="EscapeSequence">\n</span><span class="StringLit">34</span><span class="EscapeSequence">\n</span><span class="StringLit">"</span>
- <span class="Identifier">strm</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L400" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L400" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="15">
- <h1><a class="toc-backref" href="#15">Iterators</a></h1>
- <dl class="item">
- <div id="lines-iterators-all">
- <div id="lines.i,Stream">
- <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>
- <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>
- <dd>
-
- <p>Iterates over every line in the stream. The iteration is based on <tt class="docutils literal"><span class="pre">readLine</span></tt>.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#readLine,Stream">readLine(Stream) proc</a></li>
- <li><a class="reference external" href="#readLine,Stream,string">readLine(Stream, string) proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"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"</span><span class="Punctuation">)</span>
- <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>
- <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>
- <span class="Identifier">lines</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">line</span>
- <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">"The first line"</span><span class="Punctuation">,</span> <span class="StringLit">"the second line"</span><span class="Punctuation">,</span> <span class="StringLit">"the third line"</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></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/streams.nim#L1128" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/streams.nim#L1128" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:28:03 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|