Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changes between Version 4 and Version 5 of ChapterIoStreamProtocol

Show
Ignore:
Author:
kris (IP: 17.228.23.90)
Timestamp:
05/06/09 21:23:53 (5 years ago)
Comment:

updated to 0.99.8 tango.io changes

Legend:

Unmodified
Added
Removed
Modified
  • ChapterIoStreamProtocol

    v4 v5  
    22 
    33= Streams and !StreamIterators = 
    4 == Streams == 
    54 
    6 === !BufferedStream === 
     5=== Buffered === 
    76 
    8 Buffers the flow of data from a upstream input. A downstream 
    9 neighbour can locate and use this buffer instead of creating 
    10 another instance of their own. 
     7!BufferedInput and !BufferedOutput buffer the flow of data from a upstream input/output. A downstream neighbour can locate and use this buffer instead of creating another instance of their own. 
    118 
    12 (note that upstream is closer to the source, and downstream is 
    13 further away) 
     9(note that upstream is closer to the source, and downstream is further away) 
    1410 
    15 !BufferedInput, !BufferedOutput are streams buffer the flow of data from a upstream output. A downstream 
    16 neighbour can locate and use this buffer instead of creating another instance of their own. 
     11=== Data === 
    1712 
    18 === !DataFileStream === 
    19 !DataFileInput, !DataFileOutput composes a seekable file with buffer. A seek causes 
    20 the buffer to be cleared or flushed. 
    21  
    22 === !DataStream === 
    23 !DataInput[[br]] 
    24 A simple way to read binary data from an arbitrary !InputStream, such as a file: 
     13!DataInput represents a simple way to read binary data from an arbitrary !InputStream, such as a file: 
    2514{{{ 
    2615#!d 
    27 auto input = new DataInput (new FileInput("path")); 
    28 auto x = input.getInt; 
    29 auto y = input.getDouble; 
    30 input.get (new char[10]); 
     16auto input = new DataInput (new File("path")); 
     17auto x = input.int32; 
     18auto y = input.float64; 
     19char[22] tmp; 
     20auto len = input.array (tmp); 
    3121input.close; 
    3222}}} 
    3323 
    34 !DataOutput[[br]] 
    35 A simple way to write binary data to an arbitrary !OutputStream, such as a file: 
     24!DataOutput is is similar, bot for output to an arbitrary !OutputStream, such as a file: 
    3625{{{ 
    3726#!d 
    38 auto output = new DataOutput (new FileOutput("path")); 
    39 output.putInt (1024); 
    40 output.putDouble (3.14159); 
    41 output.put ("hello world"); 
     27auto output = new DataOutput (new File("path", File.WriteCreate)); 
     28output.int32 (1024); 
     29output.float64 (3.14159); 
     30output.array ("hello world"); 
    4231output.flush.close; 
    4332}}} 
    4433 
    45 === !DigestStream === 
    46 !DigestInput[[br]] 
    47 Inject a digest filter into an input stream, updating the digest as information flows through it 
     34=== !DataFile === 
    4835 
    49 !DigestOutput[[br]] 
    50 Inject a digest filter into an output stream, updating the digest as information flows through it. Here's an example where we calculate 
    51 an MD5 digest as a side-effect of copying a file: 
     36!DataFileInput and !DataFileOutput compose a seekable File with a Data class. A seek causes the buffer to be cleared or flushed. 
     37 
     38=== Digester === 
     39 
     40!DigestInput injects a digest filter into an input stream, updating the digest as information flows through it. 
     41 
     42!DigestOutput inject a digest filter into an output stream, updating the digest as information flows through it. Here's an example where we calculate an MD5 digest as a side-effect of copying a file: 
    5243{{{ 
    5344#!d 
    54 auto output = new DigestOutput(new FileOutput("output"), new Md5); 
    55 output.copy (new FileInput("input")); 
     45auto output = new DigestOutput(new File("output", File.WriteCreate), new Md5); 
     46output.copy (new File("input")); 
    5647 
    5748Stdout.formatln ("hex digest: {}", output.digest.hexDigest); 
    5849}}} 
    5950 
    60 === !EndianessStream === 
     51=== Endian === 
    6152 
    62 Streams for swapping endian-order. The stream is treated as a set 
    63 of same-sized elements. Note that partial elements are not mutated 
     53Streams for swapping endian-order. The stream is treated as a set of same-sized elements. Note that partial elements are not mutated. See !EndianInput and !EndianOutput 
    6454 
    65 !EndianInput and !EndianOutput 
     55=== Format === 
    6656 
    67 === !FileStream === 
    68  
    69 Trivial wrapper around a !FileConduit 
    70  
    71 !FileInput and !FileOutput 
    72  
    73 === !FormatStream === 
    74  
    75 Simple way to hook up a utf8 formatter to an arbitrary !OutputStream, 
    76 such as a file: 
    77  
     57Simple way to hook up a utf8 formatter to an arbitrary !OutputStream, such as a file, socket, or other: 
    7858{{{ 
    7959#!d 
    80 auto output = new FormatOutput (new FileOutput("path")); 
     60auto output = new FormatOutput!(char) (new File("path", File.WriteCreate)); 
    8161output.formatln ("{} green bottles", 10); 
    8262output.close; 
    8363}}} 
    8464 
    85 This is a trivial wrapper around the Print class, and is limited 
    86 to emitting utf8 output. Use the Print class directly in order to 
    87 generate utf16/32 output instead. 
     65This is a wrapper around the Layout class, and is typed for either char, wchar or dchar output.  
    8866 
    89 Note that this class is a true instance of !OutputStream, by way of 
    90 inheritance via the Print superclass. 
     67=== Greedy === 
    9168 
    92 === !GreedyStream === 
     69!GreedyOutput is a conduit filter that ensures its output is written in full. 
    9370 
    94 !GreedyOutput[[br]] 
    95 A conduit filter that ensures its output is written in full 
     71!GreedyInput is a conduit filter that ensures its input is read in full. 
    9672 
    97 !GreedyInput[[br]] 
    98 A conduit filter that ensures its input is read in full 
     73=== Lines === 
    9974 
    100 === !LineStream === 
    101  
    102 !LineInput[[br]] 
    103 Simple way to hook up a line-tokenizer to an arbitrary !InputStream, 
    104 such as a file conduit: 
     75Simple way to hook up a line-tokenizer to an arbitrary !InputStream, such as a file conduit: 
    10576{{{ 
    10677#!d 
    107 auto input = new LineInput (new FileInput("path")); 
     78auto input = new LineInput!(char) (new File("path")); 
    10879foreach (line; input) 
    10980            ... 
    11182}}} 
    11283 
    113 Note that this is just a simple wrapper around !LineIterator, and 
    114 supports utf8 lines only. Use !LineIterator directly for utf16/32 
    115 support, or use the other tango.text.stream classes directly for 
    116 other tokenizing needs. 
     84=== Map === 
    11785 
    118 Note that this class is a true instance of !InputStream, by way of 
    119 inheritance via the Iterator superclass. 
     86!MapInput!(T) provides load facilities for a properties stream. That is, a file or other medium containing lines of text with a name=value layout 
    12087 
    121 === !MapStream === 
     88!MapOutput!(T) provides write facilities on a properties stream. That is, a file or other medium which will contain lines of text with a name=value layout 
    12289 
    123 !MapInput!(T) 
    124 Provides load facilities for a properties stream. That is, a file 
    125 or other medium containing lines of text with a name=value layout 
     90=== Snoop === 
    12691 
    127 !MapOutput!(T) 
    128 Provides write facilities on a properties stream. That is, a file 
    129 or other medium which will contain lines of text with a name=value 
    130 layout 
     92!SnoopInput, !SnoopOutput represent streams for exposing call behaviour. By default, activity trace is sent to Cerr. This can be useful for logging/debugging the stream calls. 
    13193 
     94=== !TextFile === 
    13295 
    133 === !SnoopStream === 
     96!TextFileInput and !TextFileOutput combines a File with Text IO. 
    13497 
    135 !SnoopInput, !SnoopOutput 
    136 Streams to expose call behaviour. By default, activity trace is sent to Cerr. 
     98=== Typed === 
    13799 
    138 This is usefull for logging/debugging the stream calls
     100!TypedInput!(T) and !TypedOutput!(T) are streams to expose simple native types as discrete elements. I/O is buffered and should yield fair performance
    139101 
    140 === !TextFileStream === 
     102=== Utf === 
     103!UtfInput!(T,S) and !UtfOutput!(S,T) represent UTF conversion streams, supporting cross-translation of char, wchar and dchar variants. For supporting endian variations, configure an appropriate Endian upstream of this one (closer to the source) 
    141104 
    142 !TextFileInput and !TextFileOutput[[br]] 
    143 Composes a file with line-oriented input 
     105== Iterators == 
    144106 
    145 === !TypedStream === 
    146  
    147 !TypedInput!(T) and !TypedOutput!(T)[[br]] 
    148 Streams to expose simple native types as discrete elements. I/O is buffered and should yield fair performance. 
    149  
    150 === !UtfStream === 
    151 !UtfInput!(T,S) and !UtfOutput!(S,T)[[br]] 
    152 UTF conversion streams, supporting cross-translation of char, wchar 
    153 and dchar variants. For supporting endian variations, configure the 
    154 appropriate !EndianStream upstream of this one (closer to the source) 
    155  
    156  
    157 == Streaming Iterators == 
    158  
    159 Tango has a set of classes to split streaming text into elements matching a specific pattern. These classes operate upon an !InputStream, and are templated for char, wchar, and dchar data types. For example, there’s an iterator for producing lines of text based upon finding embedded end-of-line markers. Iterator classes are clients of Buffer, and can therefore be mixed with reader and/or writer clients also.  
     107Tango has a set of classes to split streaming text into elements matching a specific pattern. These classes operate upon an !InputStream, and are templated for char, wchar, and dchar data types. For example, there’s an iterator for producing lines of text based upon finding embedded end-of-line markers. See Delimiters, Lines, Patterns and Quotes. 
    160108 
    161109Iterator results are usually aliased directly from the containing buffer, thus avoiding heap activity where an application doesn’t need it. Where the resultant element is to be retained by the application, it should be copied before continuing.