/* fun stuff like image/video 
 *
 * these experiments will start to break request/response
 * patterns and help us to start to support streaming too
 * */

var http = require('http');

var url = "http://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png";

module.exports = function(device) {
  return {
    'tux.png (url)': {
      fn: function(cb) {
        cb(null, {
          contentType: 'image/url',
          content: url
        });
      }
    },
    'tux.png (base64)': {
      /* We'll be sending the tux image as base64 over websockets for
       * display in a canvas or img tag on the other side */
      pipe: true,
      fn: function(cb) {
        var chunks = [];
        http.get(url, function(res) {
          res.pipe(socket);
          /*
          res.on('data', function (chunk) {
            chunks.push(chunk);
          });
          res.on('end', function() {
            var result = '';
            for (var i = 0, l = chunks.length; i < l; i ++) {
              var v = chunks[i];
              result += v.toString('base64');
            }
            cb(null, {
              contentType: 'image/png',
              content: result
            });
          });
          */
        }).on('error', function(e) {
          cb(e, null);
        });
      }
    }
  };
};


@@ -615,20 +615,22 @@
 /%0A      
-pipe
+stream
 : true,%0A
@@ -654,36 +654,19 @@
 n(cb
-) %7B%0A        var chunks = %5B%5D;
+, stream) %7B
 %0A   
@@ -704,49 +704,8 @@
 ) %7B%0A
-          res.pipe(socket);%0A          /*%0A
     
@@ -760,25 +760,40 @@
     
-chunks.push(
+stream.write('stream', 
 chunk
+, %7B%7D
 );%0A 
@@ -858,272 +858,47 @@
     
-var result = '';%0A            for (var i = 0, l = chunks.length; i %3C l; i ++) %7B%0A              var v = chunks%5Bi%5D;%0A              result += v.toString('base64');%0A            %7D%0A            cb(null, %7B%0A              contentType: 'image/png',%0A              content: result
+cb(null, %7B%0A              stream: 'done'
 %0A   
@@ -928,21 +928,8 @@
 %7D);%0A
-          */%0A
     

check in some changes to fun