index.js (2539B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 /** 22 * Writable stream which inspects streamed data. 23 * 24 * @module @stdlib/streams/node/inspect-sink 25 * 26 * @example 27 * var inspectSinkStream = require( '@stdlib/streams/node/inspect-sink' ); 28 * 29 * function log( chunk, idx ) { 30 * console.log( 'index: %d', idx ); 31 * console.log( chunk ); 32 * } 33 * 34 * var stream = inspectSinkStream( log ); 35 * 36 * stream.write( 'a' ); 37 * stream.write( 'b' ); 38 * stream.write( 'c' ); 39 * 40 * stream.end(); 41 * 42 * // prints: index: 0 43 * // prints: a 44 * // prints: index: 1 45 * // prints: b 46 * // prints: index: 2 47 * // prints: c 48 * 49 * 50 * @example 51 * var inspectSinkStream = require( '@stdlib/streams/node/inspect-sink' ); 52 * 53 * function log( chunk, idx ) { 54 * console.log( 'index: %d', idx ); 55 * console.log( chunk ); 56 * } 57 * 58 * var stream = inspectSinkStream.objectMode( log ); 59 * 60 * stream.write( {'value': 'a'} ); 61 * stream.write( {'value': 'b'} ); 62 * stream.write( {'value': 'c'} ); 63 * 64 * stream.end(); 65 * 66 * // prints: index: 0 67 * // prints: {'value': 'a'} 68 * // prints: index: 1 69 * // prints: {'value': 'b'} 70 * // prints: index: 2 71 * // prints: {'value': 'c'} 72 * 73 * @example 74 * var inspectSinkStream = require( '@stdlib/streams/node/inspect-sink' ); 75 * 76 * function log( chunk, idx ) { 77 * console.log( 'index: %d', idx ); 78 * console.log( chunk ); 79 * } 80 * 81 * var opts = { 82 * 'objectMode': true, 83 * 'highWaterMark': 64 84 * }; 85 * 86 * var factory = inspectSinkStream.factory( opts ); 87 * 88 * // Create 10 identically configured streams... 89 * var streams = []; 90 * var i; 91 * for ( i = 0; i < 10; i++ ) { 92 * streams.push( factory( log ) ); 93 * } 94 */ 95 96 97 // MODULES // 98 99 var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); 100 var stream = require( './main.js' ); 101 var objectMode = require( './object_mode.js' ); 102 var factory = require( './factory.js' ); 103 104 105 // MAIN // 106 107 setReadOnly( stream, 'objectMode', objectMode ); 108 setReadOnly( stream, 'factory', factory ); 109 110 111 // EXPORTS // 112 113 module.exports = stream;