1# parallel-transform 2 3[Transform stream](http://nodejs.org/api/stream.html#stream_class_stream_transform_1) for Node.js that allows you to run your transforms 4in parallel without changing the order of the output. 5 6 npm install parallel-transform 7 8It is easy to use 9 10``` js 11var transform = require('parallel-transform'); 12 13var stream = transform(10, function(data, callback) { // 10 is the parallism level 14 setTimeout(function() { 15 callback(null, data); 16 }, Math.random() * 1000); 17}); 18 19for (var i = 0; i < 10; i++) { 20 stream.write(''+i); 21} 22stream.end(); 23 24stream.on('data', function(data) { 25 console.log(data); // prints 0,1,2,... 26}); 27stream.on('end', function() { 28 console.log('stream has ended'); 29}); 30``` 31 32If you run the above example you'll notice that it runs in parallel 33(does not take ~1 second between each print) and that the order is preserved 34 35## Stream options 36 37All transforms are Node 0.10 streams. Per default they are created with the options `{objectMode:true}`. 38If you want to use your own stream options pass them as the second parameter 39 40``` js 41var stream = transform(10, {objectMode:false}, function(data, callback) { 42 // data is now a buffer 43 callback(null, data); 44}); 45 46fs.createReadStream('filename').pipe(stream).pipe(process.stdout); 47``` 48 49### Unordered 50Passing the option `{ordered:false}` will output the data as soon as it's processed by a transform, without waiting to respect the order. 51 52## License 53 54MIT