Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another, probably more efficient way, of dumping the contents of Stdin would be something like this:</p> <pre><code>module dumpstdin; import tango.io.Console : Cin; import tango.io.device.Array : Array; import tango.io.model.IConduit : InputStream; const BufferInitialSize = 4096u; const BufferGrowingStep = 4096u; ubyte[] dumpStream(InputStream ins) { auto buffer = new Array(BufferInitialSize, BufferGrowingStep); buffer.copy(ins); return cast(ubyte[]) buffer.slice(); } import tango.io.Stdout : Stdout; void main() { auto contentsOfStdin = cast(char[]) dumpStream(Cin.stream); Stdout ("Finished reading Stdin.").newline() ("Contents of Stdin was:").newline() ("&lt;&lt;")(contentsOfStdin)("&gt;&gt;").newline(); } </code></pre> <p>Some notes:</p> <ul> <li>The second parameter to Array is necessary; if you omit it, Array will not grow in size.</li> <li>I used 4096 since that's generally the size of a page of memory.</li> <li><code>dumpStream</code> returns a <code>ubyte[]</code> because <code>char[]</code> is defined as a UTF-8 string, which Stdin doesn't necessarily need to be. For example, if someone piped a binary file to your program, you would end up with an invalid <code>char[]</code> that could throw an exception if anything checks it for validity. If you only care about text, then casting the result to a <code>char[]</code> is fine.</li> <li><code>copy</code> is a method on the <code>OutputStream</code> interface that causes it to drain the provided <code>InputStream</code> of all input.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload