repl.txt (4659B)
1 2 {{alias}}( iterator[, options] ) 3 Creates a readable stream from an iterator. 4 5 In object mode, `null` is a reserved value. If an iterator generates `null` 6 values (e.g., as a means to encode missing values), the stream will 7 prematurely end. Consider an alternative encoding or explicitly map `null` 8 values to a different value by wrapping the provided iterator with another 9 iterator. 10 11 In binary mode, if an iterator generates `undefined` values, the stream will 12 emit an error. Consider providing a custom serialization function or 13 explicitly map `undefined` values to a different value by wrapping the 14 provided iterator with another iterator. 15 16 If a serialization function fails to return a string or Buffer, the stream 17 emits an error. 18 19 Parameters 20 ---------- 21 iterator: Object 22 Source iterator. 23 24 options: Object (optional) 25 Options. 26 27 options.objectMode: boolean (optional) 28 Specifies whether a stream should operate in "objectMode". Default: 29 false. 30 31 options.encoding: string|null (optional) 32 Specifies how Buffer objects should be decoded to strings. Default: 33 null. 34 35 options.highWaterMark: integer (optional) 36 Specifies the maximum number of bytes to store in an internal buffer 37 before pausing iteration. 38 39 options.sep: string (optional) 40 Separator used to join streamed data. This option is only applicable 41 when a stream is not in "objectMode". Default: '\n'. 42 43 options.serialize: Function (optional) 44 Serialization function. The default behavior is to serialize iterated 45 values as JSON strings. This option is only applicable when a stream is 46 not in "objectMode". 47 48 Returns 49 ------- 50 stream: ReadableStream 51 Readable stream. 52 53 Examples 54 -------- 55 > function fcn( chunk ) { console.log( chunk.toString() ); }; 56 > var opts = { 'iter': 10 }; 57 > var it = {{alias:@stdlib/random/iter/randu}}( opts ); 58 > var s = {{alias}}( it ); 59 > var o = {{alias:@stdlib/streams/node/inspect-sink}}( fcn ); 60 > s.pipe( o ); 61 62 63 {{alias}}.factory( [options] ) 64 Returns a function for creating readable streams from iterators. 65 66 Parameters 67 ---------- 68 options: Object (optional) 69 Options. 70 71 options.objectMode: boolean (optional) 72 Specifies whether a stream should operate in "objectMode". Default: 73 false. 74 75 options.encoding: string|null (optional) 76 Specifies how Buffer objects should be decoded to strings. Default: 77 null. 78 79 options.highWaterMark: integer (optional) 80 Specifies the maximum number of bytes to store in an internal buffer 81 before pausing iteration. 82 83 options.sep: string (optional) 84 Separator used to join streamed data. This option is only applicable 85 when a stream is not in "objectMode". Default: '\n'. 86 87 options.serialize: Function (optional) 88 Serialization function. The default behavior is to serialize iterated 89 values as JSON strings. This option is only applicable when a stream is 90 not in "objectMode". 91 92 Returns 93 ------- 94 fcn: Function 95 Function for creating readable streams. 96 97 Examples 98 -------- 99 > var opts = { 'objectMode': true, 'highWaterMark': 64 }; 100 > var createStream = {{alias}}.factory( opts ); 101 102 103 {{alias}}.objectMode( iterator[, options] ) 104 Returns an "objectMode" readable stream from an iterator. 105 106 In object mode, `null` is a reserved value. If an iterator generates `null` 107 values (e.g., as a means to encode missing values), the stream will 108 prematurely end. Consider an alternative encoding or explicitly map `null` 109 values to a different value by wrapping the provided iterator with another 110 iterator. 111 112 Parameters 113 ---------- 114 iterator: Object 115 Source iterator. 116 117 options: Object (optional) 118 Options. 119 120 options.encoding: string|null (optional) 121 Specifies how Buffer objects should be decoded to strings. Default: 122 null. 123 124 options.highWaterMark: integer (optional) 125 Specifies the maximum number of objects to store in an internal buffer 126 before pausing iteration. 127 128 Returns 129 ------- 130 stream: ReadableStream 131 Readable stream operating in "objectMode". 132 133 Examples 134 -------- 135 > function fcn( v ) { console.log( v ); }; 136 > var opts = { 'iter': 10 }; 137 > var it = {{alias:@stdlib/random/iter/randu}}( opts ); 138 > var s = {{alias}}.objectMode( it ); 139 > var o = {{alias:@stdlib/streams/node/inspect-sink}}.objectMode( fcn ); 140 > s.pipe( o ); 141 142 See Also 143 -------- 144