Files
SwiftShell/Protocols/ReadableStream.html
2019-03-28 15:49:36 +01:00

615 lines
31 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en">
<head>
<title>ReadableStream Protocol Reference</title>
<link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="../css/highlight.css" />
<meta charset='utf-8'>
<script src="../js/jquery.min.js" defer></script>
<script src="../js/jazzy.js" defer></script>
</head>
<body>
<a name="//apple_ref/swift/Protocol/ReadableStream" class="dashAnchor"></a>
<a title="ReadableStream Protocol Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">SwiftShell Docs</a> (72% documented)</p>
<p class="header-right"><a href="https://github.com/kareman/SwiftShell"><img src="../img/gh.png"/>View on GitHub</a></p>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="../index.html">SwiftShell Reference</a>
<img id="carat" src="../img/carat.png" />
ReadableStream Protocol Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Classes/AsyncCommand.html">AsyncCommand</a>
</li>
<li class="nav-group-task">
<a href="../Classes/FileHandleStream.html">FileHandleStream</a>
</li>
<li class="nav-group-task">
<a href="../Classes/MainContext.html">MainContext</a>
</li>
<li class="nav-group-task">
<a href="../Classes/PrintedAsyncCommand.html">PrintedAsyncCommand</a>
</li>
<li class="nav-group-task">
<a href="../Classes/RunOutput.html">RunOutput</a>
</li>
<li class="nav-group-task">
<a href="../Classes/StdoutStream.html">StdoutStream</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Global Variables.html">Global Variables</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Global Variables.html#/s:10SwiftShell5FilesSo13NSFileManagerCvp">Files</a>
</li>
<li class="nav-group-task">
<a href="../Global Variables.html#/s:10SwiftShell4mainAA11MainContextCvp">main</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Enums.html">Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Enums/CommandError.html">CommandError</a>
</li>
<li class="nav-group-task">
<a href="../Enums/FileError.html">FileError</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Extensions.html">Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Extensions/FileHandle.html">FileHandle</a>
</li>
<li class="nav-group-task">
<a href="../Extensions/FileHandle.html">FileHandle</a>
</li>
<li class="nav-group-task">
<a href="../Extensions/LazyCollectionProtocol.html">LazyCollectionProtocol</a>
</li>
<li class="nav-group-task">
<a href="../Extensions/Process.html">Process</a>
</li>
<li class="nav-group-task">
<a href="../Extensions/Process.html">Process</a>
</li>
<li class="nav-group-task">
<a href="../Extensions/String.html">String</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Functions.html">Functions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell1poiy10Foundation3URLVAE_SStF">+(_:_:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell4exit_4file4lines5NeverOs5Error_p_SSSitF">exit(_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell4exit12errormessage9errorcode4file4lines5NeverOx_SiSSSitlF">exit(errormessage:errorcode:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell4open_8encodingAA14ReadableStream_p10Foundation3URLV_SSAEE8EncodingVtKF">open(_:encoding:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell4open_8encodingAA14ReadableStream_pSS_SS10FoundationE8EncodingVtKF">open(_:encoding:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell4open10forWriting9overwrite8encodingAA14WritableStream_p10Foundation3URLV_SbSSAGE8EncodingVtKF">open(forWriting:overwrite:encoding:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell4open10forWriting9overwrite8encodingAA14WritableStream_pSS_SbSS10FoundationE8EncodingVtKF">open(forWriting:overwrite:encoding:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell3run__13combineOutputAA03RunE0CSS_ypdSbtF">run(_:_:combineOutput:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell3run4bash13combineOutputAA03RunF0CSS_SbtF">run(bash:combineOutput:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell11runAndPrintyySS_ypdtKF">runAndPrint(_:_:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell11runAndPrint4bashySS_tKF">runAndPrint(bash:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell8runAsync__4file4lineAA0D7CommandCSS_ypdSSSitF">runAsync(_:_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell8runAsync4bash4file4lineAA0D7CommandCSS_SSSitF">runAsync(bash:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell16runAsyncAndPrint__4file4lineAA07PrintedD7CommandCSS_ypdSSSitF">runAsyncAndPrint(_:_:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell16runAsyncAndPrint4bash4file4lineAA07PrintedD7CommandCSS_SSSitF">runAsyncAndPrint(bash:file:line:)</a>
</li>
<li class="nav-group-task">
<a href="../Functions.html#/s:10SwiftShell7streamsAA14WritableStream_p_AA08ReadableE0_ptyF">streams()</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Protocols.html#/CommandRunning">CommandRunning</a>
</li>
<li class="nav-group-task">
<a href="../Protocols/CommandRunning.html">CommandRunning</a>
</li>
<li class="nav-group-task">
<a href="../Protocols/Context.html">Context</a>
</li>
<li class="nav-group-task">
<a href="../Protocols/ReadableStream.html">ReadableStream</a>
</li>
<li class="nav-group-task">
<a href="../Protocols/WritableStream.html">WritableStream</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Structs/CustomContext.html">CustomContext</a>
</li>
<li class="nav-group-task">
<a href="../Structs/LazySplitSequence.html">LazySplitSequence</a>
</li>
<li class="nav-group-task">
<a href="../Structs/PartialSourceLazySplitSequence.html">PartialSourceLazySplitSequence</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1>ReadableStream</h1>
<div class="declaration">
<div class="language">
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">ReadableStream</span> <span class="p">:</span> <span class="kt">AnyObject</span><span class="p">,</span> <span class="kt">TextOutputStreamable</span><span class="p">,</span> <span class="kt"><a href="../Protocols/CommandRunning.html">CommandRunning</a></span></code></pre>
</div>
</div>
<p>A stream of text. Does as much as possible lazily.</p>
</section>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamP8encodingSS10FoundationE8EncodingVvp"></a>
<a name="//apple_ref/swift/Property/encoding" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamP8encodingSS10FoundationE8EncodingVvp">encoding</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Undocumented</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="k">var</span> <span class="nv">encoding</span><span class="p">:</span> <span class="kt">String</span><span class="o">.</span><span class="kt">Encoding</span> <span class="p">{</span> <span class="k">get</span> <span class="k">set</span> <span class="p">}</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamP10filehandleSo12NSFileHandleCvp"></a>
<a name="//apple_ref/swift/Property/filehandle" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamP10filehandleSo12NSFileHandleCvp">filehandle</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Undocumented</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="k">var</span> <span class="nv">filehandle</span><span class="p">:</span> <span class="kt">FileHandle</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamP8readSomeSSSgyF"></a>
<a name="//apple_ref/swift/Method/readSome()" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamP8readSomeSSSgyF">readSome()</a>
</code>
<span class="declaration-note">
Default implementation
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>All the text the stream contains so far.
If the source is a file this will read everything at once.
If the stream is empty and still open this will wait for more content or end-of-file.</p>
</div>
<h4>Default Implementation</h4>
<div class="default_impl abstract">
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">readSome</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">String</span><span class="p">?</span></code></pre>
</div>
</div>
<div>
<h4>Return Value</h4>
<p>more text from the stream, or nil if we have reached the end.</p>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamP4readSSyF"></a>
<a name="//apple_ref/swift/Method/read()" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamP4readSSyF">read()</a>
</code>
<span class="declaration-note">
Default implementation
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Reads everything at once.</p>
</div>
<h4>Default Implementation</h4>
<div class="default_impl abstract">
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">read</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">String</span></code></pre>
</div>
</div>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE5liness12LazySequenceVys03AnyG0VySSGGyF"></a>
<a name="//apple_ref/swift/Method/lines()" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE5liness12LazySequenceVys03AnyG0VySSGGyF">lines()</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Splits stream lazily into lines.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">lines</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">LazySequence</span><span class="o">&lt;</span><span class="kt">AnySequence</span><span class="o">&lt;</span><span class="kt">String</span><span class="o">&gt;&gt;</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE5write2toyqd__z_ts010TextOutputD0Rd__lF"></a>
<a name="//apple_ref/swift/Method/write(to:)" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE5write2toyqd__z_ts010TextOutputD0Rd__lF">write(to:)</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Writes the text in this stream to the given TextOutputStream.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="n">write</span><span class="o">&lt;</span><span class="kt">Target</span><span class="o">&gt;</span><span class="p">(</span><span class="n">to</span> <span class="nv">target</span><span class="p">:</span> <span class="k">inout</span> <span class="kt">Target</span><span class="p">)</span> <span class="k">where</span> <span class="kt">Target</span> <span class="p">:</span> <span class="kt">TextOutputStream</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE5write2toyAA08WritableD0_pz_tF"></a>
<a name="//apple_ref/swift/Method/write(to:)" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE5write2toyAA08WritableD0_pz_tF">write(to:)</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Writes the text in this stream to the given WritableStream.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">write</span><span class="p">(</span><span class="n">to</span> <span class="nv">target</span><span class="p">:</span> <span class="k">inout</span> <span class="kt"><a href="../Protocols/WritableStream.html">WritableStream</a></span><span class="p">)</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE7contextAA7Context_pvp"></a>
<a name="//apple_ref/swift/Property/context" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE7contextAA7Context_pvp">context</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Undocumented</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">context</span><span class="p">:</span> <span class="kt"><a href="../Protocols/Context.html">Context</a></span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE12readSomeData10Foundation0G0VSgyF"></a>
<a name="//apple_ref/swift/Method/readSomeData()" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE12readSomeData10Foundation0G0VSgyF">readSomeData()</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>All the data the stream contains so far.
If the source is a file this will read everything at once.
If the stream is empty and still open this will wait for more content or end-of-file.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">readSomeData</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Data</span><span class="p">?</span></code></pre>
</div>
</div>
<div>
<h4>Return Value</h4>
<p>more data from the stream, or nil if we have reached the end.</p>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE8readData10Foundation0F0VyF"></a>
<a name="//apple_ref/swift/Method/readData()" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE8readData10Foundation0F0VyF">readData()</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Reads everything at once.
Marked with @discardableResult so that the stream can be read before
calling .finish() without causing any compiler warnings or requiring
developer work-arounds when the result will not be used (see #52 &amp; #57)</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">readData</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Data</span></code></pre>
</div>
</div>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE8onOutputyyyAaB_pcF"></a>
<a name="//apple_ref/swift/Method/onOutput(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE8onOutputyyyAaB_pcF">onOutput(_:)</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Sets code to be executed whenever there is new output available.</p>
<div class="aside aside-note">
<p class="aside-title">Note</p>
if the stream is read from outside of <code>handler</code>, or more than once inside
it, it may be called once when stream is closed and empty.
</div>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">onOutput</span><span class="p">(</span><span class="n">_</span> <span class="nv">handler</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">ReadableStream</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:10SwiftShell14ReadableStreamPAAE14onStringOutputyyySScF"></a>
<a name="//apple_ref/swift/Method/onStringOutput(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:10SwiftShell14ReadableStreamPAAE14onStringOutputyyySScF">onStringOutput(_:)</a>
</code>
<span class="declaration-note">
Extension method
</span>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Sets code to be executed whenever there is new text output available.</p>
<div class="aside aside-note">
<p class="aside-title">Note</p>
if the stream is read from outside of <code>handler</code>, or more than once inside
it, it may be called once when stream is closed and empty.
</div>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">onStringOutput</span><span class="p">(</span><span class="n">_</span> <span class="nv">handler</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">String</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>
</div>
</div>
</section>
</div>
</li>
</ul>
</div>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="" target="_blank" rel="external">kareman</a>. All rights reserved. (Last updated: 2019-03-28)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.5</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>