index.js (2048B)
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 * Transform stream which splits streamed data. 23 * 24 * @module @stdlib/streams/node/split 25 * 26 * @example 27 * var stdout = require( '@stdlib/streams/node/stdout' ); 28 * var splitStream = require( '@stdlib/streams/node/split' ); 29 * 30 * var stream = splitStream(); 31 * 32 * stream.pipe( stdout ); 33 * 34 * stream.write( '1\n2\n3' ); 35 * stream.end(); 36 * // => '1' => '2' => '3' 37 * 38 * @example 39 * var splitStream = require( '@stdlib/streams/node/split' ); 40 * 41 * var opts = { 42 * 'sep': '\t', 43 * 'objectMode': true, 44 * 'encoding': 'utf8', 45 * 'highWaterMark': 64 46 * }; 47 * 48 * var factory = splitStream.factory( opts ); 49 * 50 * // Create 10 identically configured streams... 51 * var streams = []; 52 * var i; 53 * for ( i = 0; i < 10; i++ ) { 54 * streams.push( factory() ); 55 * } 56 * 57 * @example 58 * var stdout = require( '@stdlib/streams/node/stdout' ); 59 * var splitStream = require( '@stdlib/streams/node/split' ); 60 * 61 * var stream = splitStream.objectMode({ 62 * 'sep': ',' 63 * }); 64 * 65 * stream.pipe( stdout ); 66 * 67 * stream.write( 'a,b,c' ); 68 * stream.end(); 69 * // => 'a' => 'b' => 'c' 70 */ 71 72 73 // MODULES // 74 75 var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); 76 var stream = require( './main.js' ); 77 var objectMode = require( './object_mode.js' ); 78 var factory = require( './factory.js' ); 79 80 81 // MAIN // 82 83 setReadOnly( stream, 'objectMode', objectMode ); 84 setReadOnly( stream, 'factory', factory ); 85 86 87 // EXPORTS // 88 89 module.exports = stream;