dcat/doc/api/dcat/cat.html

220 lines
9.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
<meta name="description" content="API docs for the cat function from the dcat library, for the Dart programming language.">
<title>cat function - dcat library - Dart API</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="../static-assets/github.css?v1">
<link rel="stylesheet" href="../static-assets/styles.css?v1">
<link rel="icon" href="../static-assets/favicon.png?v1">
</head>
<body data-base-href="../"
data-using-base-href="false">
<div id="overlay-under-drawer"></div>
<header id="title">
<button id="sidenav-left-toggle" type="button">&nbsp;</button>
<ol class="breadcrumbs gt-separated dark hidden-xs">
<li><a href="../index.html">dcat</a></li>
<li><a href="../dcat/dcat-library.html">dcat</a></li>
<li class="self-crumb">cat function</li>
</ol>
<div class="self-name">cat</div>
<form class="search navbar-right" role="search">
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
</form>
</header>
<main>
<div id="dartdoc-main-content" class="main-content">
<div>
<h1><span class="kind-function">cat</span> function
<a href="https://dart.dev/null-safety" class="feature feature-null-safety" title="Supports the null safety language feature.">Null safety</a>
</h1></div>
<section class="multi-line-signature">
<span class="returntype"><a href="https://api.dart.dev/stable/2.14.3/dart-async/Future-class.html">Future</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../dcat/CatResult-class.html">CatResult</a></span>&gt;</span></span>
<span class="name ">cat</span>(<wbr><ol class="parameter-list"><li><span class="parameter" id="cat-param-paths"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>&gt;</span></span> <span class="parameter-name">paths</span>, </span></li>
<li><span class="parameter" id="cat-param-output"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object-class.html">Object</a></span> <span class="parameter-name">output</span>, </span></li>
<li><span class="parameter" id="cat-param-input">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-async/Stream-class.html">Stream</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>&gt;</span></span>&gt;</span>?</span> <span class="parameter-name">input</span>, </span></li>
<li><span class="parameter" id="cat-param-log"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>&gt;</span>?</span> <span class="parameter-name">log</span>, </span></li>
<li><span class="parameter" id="cat-param-showEnds"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showEnds</span> = <span class="default-value">false</span>, </span></li>
<li><span class="parameter" id="cat-param-numberNonBlank"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">numberNonBlank</span> = <span class="default-value">false</span>, </span></li>
<li><span class="parameter" id="cat-param-showLineNumbers"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showLineNumbers</span> = <span class="default-value">false</span>, </span></li>
<li><span class="parameter" id="cat-param-showTabs"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showTabs</span> = <span class="default-value">false</span>, </span></li>
<li><span class="parameter" id="cat-param-squeezeBlank"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">squeezeBlank</span> = <span class="default-value">false</span>, </span></li>
<li><span class="parameter" id="cat-param-showNonPrinting"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showNonPrinting</span> = <span class="default-value">false</span>}</span></li>
</ol>)
</section>
<section class="desc markdown">
<p>Concatenates files in <code>paths</code> to <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdout.html">stdout</a> or <a href="https://api.dart.dev/stable/2.14.3/dart-io/File-class.html">File</a>.</p>
<ul>
<li><code>output</code> should be an <a href="https://api.dart.dev/stable/2.14.3/dart-io/IOSink-class.html">IOSink</a> like <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdout.html">stdout</a> or a <a href="https://api.dart.dev/stable/2.14.3/dart-io/File-class.html">File</a>.</li>
<li><code>input</code> can be <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdin.html">stdin</a>.</li>
<li><code>log</code> is used for debugging/testing purposes.</li>
</ul>
<p>The remaining optional parameters are similar to the <a href="https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation">GNU cat utility</a>.</p>
</section>
<section class="summary source-code" id="source">
<h2><span>Implementation</span></h2>
<pre class="language-dart"><code class="language-dart">Future&lt;CatResult&gt; cat(List&lt;String&gt; paths, Object output,
{Stream&lt;List&lt;int&gt;&gt;? input,
List&lt;String&gt;? log,
bool showEnds = false,
bool numberNonBlank = false,
bool showLineNumbers = false,
bool showTabs = false,
bool squeezeBlank = false,
bool showNonPrinting = false}) async {
var result = CatResult();
var lineNumber = 1;
log?.clear();
if (paths.isEmpty) {
if (input != null) {
final lines = await _readStream(input);
try {
await _writeLines(
lines,
lineNumber,
output,
log,
showEnds,
showLineNumbers,
numberNonBlank,
showTabs,
squeezeBlank,
showNonPrinting);
} catch (e) {
result.addMessage(exitFailure, &#39;$e&#39;);
}
}
} else {
for (final path in paths) {
try {
final Stream&lt;String&gt; lines;
if (path == &#39;-&#39; &amp;&amp; input != null) {
lines = await _readStream(input);
} else {
lines = utf8.decoder
.bind(File(path).openRead())
.transform(const LineSplitter());
}
lineNumber = await _writeLines(
lines,
lineNumber,
output,
log,
showEnds,
showLineNumbers,
numberNonBlank,
showTabs,
squeezeBlank,
showNonPrinting);
} on FileSystemException catch (e) {
final String? osMessage = e.osError?.message;
final String message;
if (osMessage != null &amp;&amp; osMessage.isNotEmpty) {
message = osMessage;
} else {
message = e.message;
}
result.addMessage(exitFailure, message, path: path);
} on FormatException {
result.addMessage(exitFailure, &#39;Binary file not supported.&#39;,
path: path);
} catch (e) {
result.addMessage(exitFailure, &#39;$e&#39;, path: path);
}
}
}
return result;
}</code></pre>
</section>
</div> <!-- /.main-content -->
<div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
<header id="header-search-sidebar" class="hidden-l">
<form class="search-sidebar" role="search">
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
</form>
</header>
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
<li><a href="../index.html">dcat</a></li>
<li><a href="../dcat/dcat-library.html">dcat</a></li>
<li class="self-crumb">cat function</li>
</ol>
<h5>dcat library</h5>
<ol>
<li class="section-title"><a href="../dcat/dcat-library.html#classes">Classes</a></li>
<li><a href="../dcat/CatResult-class.html">CatResult</a></li>
<li class="section-title"><a href="../dcat/dcat-library.html#constants">Constants</a></li>
<li><a href="../dcat/exitFailure-constant.html">exitFailure</a></li>
<li><a href="../dcat/exitSuccess-constant.html">exitSuccess</a></li>
<li class="section-title"><a href="../dcat/dcat-library.html#functions">Functions</a></li>
<li><a href="../dcat/cat.html">cat</a></li>
</ol>
</div><!--/.sidebar-offcanvas-left-->
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
</div><!--/.sidebar-offcanvas-->
</main>
<footer>
<span class="no-break">
dcat
1.0.0
</span>
</footer>
<script src="../static-assets/highlight.pack.js?v1"></script>
<script src="../static-assets/script.js?v1"></script>
</body>
</html>