Example #1
0
exports.run = function (args) {
    process.stdin.pipe(concat(function (body) {
        Function(injectWindow + body.toString())();
    }));
};
Example #2
0
File: rest.js Project: 6a68/dat
 function (cb) {
   request({uri: 'http://localhost:' + dat.options.port + '/api/rows?format=ndjson'})
     .pipe(ldj.parse())
     .pipe(concat(commonFormatTest.bind(null, cb, 'format=ndjson')))
 },
Example #3
0
File: rest.js Project: 6a68/dat
 function(cb) {
   request({uri: 'http://localhost:' + dat.options.port + '/api/changes?tail=1&data=true&style=newline'})
     .pipe(ldj.parse())
     .pipe(concat(formatTest.bind(null, cb, 'style=newline (legacy)')))
 },
Example #4
0
#!/usr/bin/env node

var spawn = require('child_process').spawn
var concat = require('concat-stream')

var ref = spawn('git', ['reflog', 'show', 'origin/master'])


ref.stdout.pipe(concat(onRef))

function onRef(output) {
  var ref = output.toString().trim()
  if (ref.match("update by push"))
  console.log(true)
  else console.log(false)
}

// check via the github api? would need username
// and repo name (repo name could be assumed/gotten
// via the name of the current directory locally)

// git show-branch origin/master

// var remote = spawn('git', ['show-branch', 'origin/master'])

// If commits but no remote pushes
//
// jlord:test jessicalord$ git show-branch origin/master
// fatal: bad sha1 reference origin/master

// If empty git repo, no commits
Example #5
0
Browserify.prototype.bundle = function (opts, cb) {
    var self = this;
    if (typeof opts === 'function') {
        cb = opts;
        opts = {};
    }
    if (!opts) opts = {};
    if (opts.insertGlobals === undefined) opts.insertGlobals = false;
    if (opts.detectGlobals === undefined) opts.detectGlobals = true;
    if (opts.ignoreMissing === undefined) opts.ignoreMissing = false;
    if (opts.standalone === undefined) opts.standalone = false;
    
    self._ignoreMissing = opts.ignoreMissing;
    
    opts.resolve = self._resolve.bind(self);
    opts.transform = self._transforms;
    
    var basedir = opts.basedir || self._basedir;
    if (!basedir && self._commondir === false) {
        basedir = '/';
    }
    else if (!basedir && self.files.length === 1) {
        basedir = path.dirname(self.files[0]);
    }
    else if (!basedir && self.files.length === 0) {
        basedir = process.cwd();
    }
    else if (!basedir) basedir = commondir(self.files);
    
    if (opts.detectGlobals || opts.insertGlobals) {
        opts.globalTransform = [ function (file) {
            if (self._noParse.indexOf(file) >= 0) {
                return through();
            }
            return insertGlobals(file, {
                always: opts.insertGlobals,
                vars: opts.insertGlobalVars,
                basedir: basedir
            });
        } ].concat(self._globalTransforms);
    }
    else opts.globalTransform = self._globalTransforms;
    
    opts.noParse = self._noParse;
    opts.transformKey = [ 'browserify', 'transform' ];
    
    var parentFilter = opts.packageFilter;
    opts.packageFilter = function (pkg) {
        if (parentFilter) pkg = parentFilter(pkg || {});
        return packageFilter(pkg || {});
    };

    if (cb) cb = (function (f) {
        return function () {
            if (f) f.apply(this, arguments);
            f = null;
        };
    })(cb);

    if (self._pending) {
        var tr = through();
        self.on('_ready', function () {
            var b = self.bundle(opts, cb);
            b.on('transform', tr.emit.bind(tr, 'transform'));
            if (!cb) b.on('error', tr.emit.bind(tr, 'error'));
            b.pipe(tr);
        });
        return tr;
    }

    if (opts.standalone && self._entries.length !== 1) {
        process.nextTick(function () {
            p.emit('error', 'standalone only works with a single entry point');
        });
    }
    
    var prevCache = opts.cache && copy(opts.cache);
    var d = (opts.deps || self.deps.bind(self))(opts);
    var p = self.pack(opts);
    if (cb) {
        p.on('error', cb);
        p.pipe(concatStream({ encoding: 'string' }, function (src) {
            cb(null, opts.standalone ? derequire(src) : src);
        }));
    }
    d.on('error', p.emit.bind(p, 'error'));
    d.on('transform', p.emit.bind(p, 'transform'));
    d.pipe(p);
    
    if (opts.standalone) {
        var output = through();
        p.pipe(concatStream({ encoding: 'string' }, function (body) {
            output.end(derequire(body));
        }));
        return output;
    }
    
    self.emit('bundle', p);
    return p;
};
Example #6
0
 domain.run(function () {
   req.pipe(concat(function (body) {
     body = JSON.parse(body);
     var files = [ ];
     var filePath = '/' + body.dir + '/' + body.sub;
     var exts = body.exts;
     // series
     var read_directory = domain.bind(function (currPath, currVirtualPath, cb) {
       fs.readdir(currPath, domain.bind(function (err, diskFiles) {
         if (err) {
           if(err.errno === 34) { cb({ code: 404, msg: 'path not found'}); } else {
             if (err.errno === 27) { cb({ code: 403, msg: 'resource is not a path'}); } else {
               cb({ code: 500, msg: 'error reading directory, are you root?'});
             }
           }
         } else {
           // map
           async.forEach(diskFiles, domain.bind(function (file, cb) {
             var virtualFile = path(currVirtualPath + '/' + file);
             var diskFile = path.normalize(currPath + '/' + file);
             fs.stat(diskFile, domain.bind(function (err, stats) {
               if (err) { cb({ code: 500, msg: 'error getting file stats' }); } else {
                 if (stats.isDirectory()) {
                   files.push({
                     name: file,
                     path: currVirtualPath,
                     dir: true
                   });
                   cb();
                 } else {
                   var getContent = false;
                   var fileExt = path.extname(diskFile);
                   if (fileExt) { fileExt = fileExt.toLowerCase(); }
                   exts.forEach( function (ext) {
                     if (ext === fileExt) {
                       getContent = true;
                     }
                   });
                   if (!getContent) {
                     files.push({
                       name: file,
                       path: currVirtualPath,
                       dir: false
                     });
                     cb();
                   } else {
                     fs.readFile(diskFile, 'utf8', domain.bind(function (err, content) {
                       if (err) { cb({ code: 500, msg: 'error reading file from disk' }); } else {
                         files.push({
                           name: file,
                           path: currVirtualPath,
                           dir: false,
                           content: content
                         });
                         cb();
                       }
                     }));
                   }
                 }
               }
             }));
           }), domain.bind(function (err) {
             if (err) {
               cb({ code: 500, msg: 'error reading files from container'});
             } else {
               cb(null, files);
             }
           }));
         }
       }));
     });
     read_directory(filePath, subDir, function (err, files) {
       if (err) { res.json(err.code, { message: err.msg }); } else {
         res.json(201, files);
       }
     });
   }));
 });
Example #7
0
var concat = require('concat-stream')
process.stdin.pipe(concat(function(body){
   var s = body.toString().split('').reverse().join('')  
   console.log(s)
}))
var concat = require('concat-stream');

process.stdin
  .pipe(concat(function (input) {
    var reversed = input.toString().split('').reverse().join('');
    console.log(reversed);
  }))
;
Example #9
0
module.exports = function parse (modules, opts) {
    if (!opts) opts = {};
    var vars = opts.vars || {};
    var varNames = opts.varNames || {};
    var skip = opts.skip || {};
    var skipOffset = opts.skipOffset || 0;
    var updates = [];
    
    function pushUpdate (node, s) {
        var rep = String(s);
        var prev = node.range[1] - node.range[0];
        updates.push({ offset: prev - rep.length });
        node.update(rep);
    }
    
    var output = through();
    var body;
    return duplexer(concat(function (buf) {
        try {
            body = buf.toString('utf8');
            var src = falafel(body, walk)
        }
        catch (err) { return error(err) }
        finish(src);
    }), output);
    
    function finish (src) {
        var offset = 0, pos = 0;
        src = String(src);
        
        (function next () {
            if (updates.length === 0) return done();
            
            var s = updates.shift();
            if (!s.stream) {
                offset += s.offset;
                return next();
            }
            
            output.push(src.slice(pos, s.range[0] - offset));
            pos = s.range[0] - offset;
            offset += s.range[1] - s.range[0];
            
            s.stream.on('end', next);
            s.stream.pipe(output, { end: false });
        })();
        
        function done () {
            output.push(src.slice(pos));
            output.push(null);
        }
    }
    
    function error (msg) {
        var err = typeof msg === 'string' ? new Error(msg) : msg;
        output.emit('error', err);
    }
    
    function walk (node) {
        var isreq = false, reqid;
        if (isRequire(node)) {
            reqid = node.arguments[0].value;
            isreq = has(modules, reqid);
        }
        
        if (isreq && node.parent.type === 'VariableDeclarator'
        && node.parent.id.type === 'Identifier') {
            varNames[node.parent.id.name] = reqid;
            var decs = node.parent.parent.declarations;
            var ix = decs.indexOf(node.parent);
            var dec;
            if (ix >= 0) {
                dec = decs[ix];
                decs.splice(ix, 1);
            }
            
            var rep;
            if (decs.length === 0) {
                rep = '';
            }
            else {
                var src = unparse(node.parent.parent);
                updates.push({
                    range: [ 0, src.length ],
                    stream: st('var ')
                });
                decs.forEach(function (d, i) {
                    var key = (d.range[0] + skipOffset)
                        + ',' + (d.range[1] + skipOffset)
                    ;
                    skip[key] = true;
                    
                    var s = parse(modules, {
                        skip: skip,
                        skipOffset: skipOffset + d.init.range[0],
                        vars: vars,
                        varNames: varNames
                    });
                    updates.push({
                        range: [
                            d.init.range[0],
                            d.init.range[1]
                        ],
                        stream: s
                    });
                    if (i < decs.length - 1) {
                        var comma;
                        if (i === ix - 1) {
                            comma = body.slice(d.range[1], dec.range[0]);
                        }
                        else comma = body.slice(d.range[1], decs[i+1].range[0]);
                        updates.push({
                            range: [
                                d.range[1], d.range[1] + comma.length
                            ],
                            stream: st(comma)
                        });
                    }
                    s.end(unparse(d));
                });
                rep = '';
            }
            pushUpdate(node.parent.parent, rep);
        }
        else if (isreq && node.parent.type === 'AssignmentExpression'
        && node.parent.left.type === 'Identifier') {
            varNames[node.parent.left.name] = reqid;
            var cur = node.parent.parent;
            if (cur.type === 'SequenceExpression') {
                var ex = cur.expressions;
                var ix = ex.indexOf(node.parent);
                if (ix >= 0) ex.splice(ix, 1);
                pushUpdate(
                    node.parent.parent,
                    unparse(node.parent.parent)
                );
            }
            else pushUpdate(cur, '');
        }
        else if (isreq && node.parent.type === 'MemberExpression'
        && node.parent.property.type === 'Identifier'
        && node.parent.parent.type === 'VariableDeclarator'
        && node.parent.parent.id.type === 'Identifier') {
            varNames[node.parent.parent.id.name] = [
                reqid, node.parent.property.name
            ];
            var decs = node.parent.parent.parent.declarations;
            var ix = decs.indexOf(node.parent.parent);
            if (ix >= 0) decs.splice(ix, 1);
            
            if (decs.length === 0) {
                pushUpdate(node.parent.parent.parent, '');
            }
            else {
                pushUpdate(
                    node.parent.parent.parent,
                    unparse(node.parent.parent.parent)
                );
            }
        }
        else if (isreq && node.parent.type === 'MemberExpression'
        && node.parent.property.type === 'Identifier') {
            var name = node.parent.property.name;
            var cur = copy(node.parent.parent);
            cur.callee = copy(node.parent.property);
            cur.callee.parent = cur;
            traverse(cur.callee, modules[reqid][name]);
        }
        else if (isreq && node.parent.type === 'CallExpression') {
            var cur = copy(node.parent);
            var iname = Math.pow(16,8) * Math.random();
            cur.callee = {
                type: 'Identifier',
                name: '_' + Math.floor(iname).toString(16),
                parent: cur
            };
            traverse(cur.callee, modules[reqid]);
        }
        
        if (node.type === 'Identifier' && has(varNames, node.name)) {
            var vn = varNames[node.name];
            if (Array.isArray(vn)) {
                traverse(node, modules[vn[0]][vn[1]]);
            }
            else traverse(node, modules[vn]);
        }
    }
    
    function traverse (node, val) {
        for (var p = node; p; p = p.parent) {
            if (!p.range) continue;
            var key = (p.range[0] + skipOffset)
                + ',' + (p.range[1] + skipOffset)
            ;
            if (skip[key]) {
                skip[key] = false;
                return;
            }
        }
        
        if (skip[key]) {
            skip[key] = false;
            return;
        }
        
        if (node.parent.type === 'CallExpression') {
            if (typeof val !== 'function') {
                return error(
                    'tried to statically call ' + inspect(val)
                    + ' as a function'
                );
            }
            var xvars = copy(vars);
            xvars[node.name] = val;
            var res = evaluate(node.parent, xvars);
            
            if (isStream(res)) {
                updates.push({
                    range: node.parent.range,
                    stream: wrapStream(res)
                });
                pushUpdate(node.parent, '');
            }
            else if (res !== undefined) pushUpdate(node.parent, res);
        }
        else if (node.parent.type === 'MemberExpression') {
            if (node.parent.property.type !== 'Identifier') {
                return error(
                    'dynamic property in member expression: '
                    + node.parent.source()
                );
            }
            
            var cur = node.parent.parent;
            
            if (cur.type === 'MemberExpression') {
                cur = cur.parent;
                if (cur.type !== 'CallExpression'
                && cur.parent.type === 'CallExpression') {
                    cur = cur.parent;
                }
            }
            if (node.parent.type === 'MemberExpression'
            && (cur.type !== 'CallExpression'
            && cur.type !== 'MemberExpression')) {
                cur = node.parent;
            }
            
            var xvars = copy(vars);
            xvars[node.name] = val;
            
            var res = evaluate(cur, xvars);
            if (isStream(res)) {
                updates.push({
                    range: cur.range,
                    stream: wrapStream(res)
                });
                cur.update('');
            }
            else if (res !== undefined) {
                pushUpdate(cur, res);
            }
        }
        else {
            output.emit('error', new Error(
                'unsupported type for static module: ' + node.parent.type
                + '\nat expression:\n\n  ' + unparse(node.parent) + '\n'
            ));
        }
    }
}
Example #10
0
var concat = require('concat-stream');

process.stdin.pipe(concat(function(data) {
  console.log(data.toString().split('').reverse().join(''))
}));
Example #11
0
 http.get(servers.proxiedUrl, function(res) {
     res.pipe(concat(function(actual) {
         servers.kill();
         t.same(actual.toString(), expected);
     }));
 }).on('error', function(e) {
Example #12
0
 controller.registerCall("icheques::fidc::enter", function (file) {
     fileReaderStream(file).pipe(concat(function (buffer) {
         var lines = buffer.toString().split("\r\n");
         readExtension[TEST_BAN_EXTENSION.exec(file.name)[1].toLowerCase()](lines);
     }));
 });
Example #13
0
    read: function (fd, cb) {

      var prefix = fd;

      var client = knox.createClient({
        key: globalOpts.key,
        secret: globalOpts.secret,
        bucket: globalOpts.bucket,
        region: globalOpts.region||undefined,
        endpoint: globalOpts.endpoint||undefined
      });

      // Build a noop transform stream that will pump the S3 output through
      var __transform__ = new Transform();
      __transform__._transform = function (chunk, encoding, callback) {
        return callback(null, chunk);
      };

      client.get(prefix).on('response', function(s3res){
        // Handle explicit s3res errors
        s3res.once('error', function (err) {
          __transform__.emit('error', err);
        });

        // check whether we got an actual file stream:
        if (s3res.statusCode < 300) {
          s3res.pipe(__transform__);
        }
        // or an error:
        else {
          // Wait for the body of the error message to stream in:
          var body = '';
          s3res.setEncoding('utf8');
          s3res.on('readable', function (){
            var chunk = s3res.read();
            if (typeof chunk === 'string') body += chunk;
          });
          // Then build the error and emit it
          s3res.once('end', function () {
            var err = new Error();
            err.status = s3res.statusCode;
            err.headers = s3res.headers;
            err.message = 'Non-200 status code returned from S3 for requested file.';
            if (body) err.message += ('\n'+body);
            __transform__.emit('error', err);
          });
        }
      })
      .end();

      if (cb) {
        var firedCb;
        __transform__.once('error', function (err) {
          if (firedCb) return;
          firedCb = true;
          cb(err);
        });
        __transform__.pipe(concat(function (data) {
          if (firedCb) return;
          firedCb = true;
          cb(null, data);
        }));
      }

      return __transform__;
    },
Example #14
0
    ls: function (dirname, cb) {
      var client = knox.createClient({
        key: globalOpts.key,
        secret: globalOpts.secret,
        bucket: globalOpts.bucket,
        region: globalOpts.region,
        endpoint: globalOpts.endpoint
      });

      // TODO: take a look at maxKeys
      // https://www.npmjs.org/package/s3-lister

      // Allow empty dirname (defaults to `/`)
      if (!dirname) {
        prefix='/';
      }
      else prefix = dirname;

      // Strip leading slash from dirname to form prefix
      var prefix = dirname.replace(/^\//, '');

      var lister = new S3Lister(client, {
        prefix : prefix
      });

      if (!cb) {
        return lister;
      }
      else {
        var firedCb;
        lister.once('error', function (err) {
          if(firedCb)return;
          firedCb=true;
          cb(err);
        });
        lister.pipe(concat(function (data) {
          if(firedCb)return;
          firedCb=true;

          // Pluck just the "Key" (i.e. file path)
          // and return only the filename (i.e. snip
          // off the path prefix)
          data = _.pluck(data, 'Key');
          data = _.map(data, function snipPathPrefixes (thisPath) {
            thisPath = thisPath.replace(/^.*[\/]([^\/]*)$/, '$1');

            // Join the dirname with the filename
            thisPath = path.join(dirname, path.basename(thisPath));

            return thisPath;
          });



          // console.log('______ files _______\n', data);
          cb(null, data);
        }));

        // TODO: marshal each matched file in the stream
        // (using a Transform- take a look at all the
        //  "plucking" and stuff I have going on above ^)
        return lister;
      }
    },
Example #15
0
function loaded(res) {
    res.pipe(concat(processXML));
}
Example #16
0
File: index.js Project: jden/2f1a
function login(req, res) {
  req.pipe(concat(function (rbody) {

    var body = JSON.parse(rbody)
    console.log(body)

    if (!body || !body.username || !body.phone) {
      res.statusCode = 400
      res.end()
      return
    }

    var phone = parsePhone(body.phone)
    if (!phone) {
      res.statusCode = 400
      res.end('invalid phone')
      return
    }

    var timeout = setTimeout(function () {
      res.statusCode = 419 // wikipedia says it's authentication timeout so it must be true
                           // [citation required]
      res.end(JSON.stringify({disposition: 'timeout'}))
      cleanup()
    }, authnTimeoutLength)

    function cleanup() {
      if (timeout) {
        clearTimeout(timeout)
      }
      // end listening for authn event

    }

    makeRandomToken(function (err, token) {
      if (err) {
        res.statusCode = 500
        console.log(err)
        return res.end('error')
      }

      console.log('authing ' + token)
      console.log('http://localhost:7001/confirm/'+token)

      sendSMS(phone, 'To continue logging on to the service, visit ' + process.env.BASE_URL + '/confirm/'+token + '. If you did not try logging on, reply NO')

      bus.on('auth:'+token, function () {
        cleanup()
        res.setHeader('content-type','application/json')
        res.end(JSON.stringify({disposition: 'ok'}))
      })
    })


  }))
  .on('error', function (e) {
    res.statusCode = 500
    res.end('error')
    console.error(e)
  })
}
Example #17
0
 domain.run(function () {
   req.pipe(concat(function (body) {
     body = JSON.parse(body);
     var files = [ ];
     var filePath = path.normalize('/' + body.dir);
     var ignores = body.ignores;
     var exts = body.exts;
     // findit -> filter -> async.map
     var read_directory = domain.bind(function (currPath, currVirtualPath, cb) {
       fs.readdir(currPath, domain.bind(function (err, diskFiles) {
         if (err) { cb({ code: 500, msg: 'error reading directory, are you root?'}); } else {
           // filer, map
           async.forEach(diskFiles, domain.bind(function (file, cb) {
             var virtualFile = path.normalize(currVirtualPath + '/' + file);
             var diskFile = path.normalize(currPath + '/' + file);
             var ignored = false;
             if (/^\./.test(file)) {
               ignored = true;
             } else {
               ignores.forEach(function (ignore) {
                 if (ignore.indexOf(virtualFile) !== -1) {
                   ignored = true;
                 }
               });
             }
             if (ignored) { cb(); } else {
               fs.stat(diskFile, domain.bind(function (err, stats) {
                 if (err) { cb({ code: 500, msg: 'error getting file stats' }); } else {
                   if (stats.isDirectory()) {
                     files.push({
                       name: file,
                       path: currVirtualPath,
                       dir: true
                     });
                     read_directory(diskFile, virtualFile, cb);
                   } else {
                     var getContent = false;
                     var fileExt = path.extname(diskFile);
                     if (fileExt) { fileExt = fileExt.toLowerCase(); }
                     exts.forEach( function (ext) {
                       if (ext === fileExt) {
                         getContent = true;
                       }
                     });
                     if (getContent) {
                       fs.readFile(diskFile, 'utf8', domain.bind(function (err, content) {
                         if (err) { cb({ code: 500, msg: 'error reading file from disk' }); } else {
                           files.push({
                             name: file,
                             path: currVirtualPath,
                             dir: false,
                             content: content
                           });
                           cb();
                         }
                       }));
                     } else {
                       files.push({
                         name: file,
                         path: currVirtualPath,
                         dir: false
                       });
                       cb();
                     }
                   }
                 }
               }));
             }
           }), domain.bind(function (err) {
             if (err) {
               cb({ code: 500, msg: 'error reading files from container'});
             } else {
               cb(null, files);
             }
           }));
         }
       }));
     });
     read_directory(filePath, '/', function (err, files) {
       if (err) { res.json(err.code, { message: err.msg }); } else {
         res.json(201, files);
       }
     });
   }));
 });
Example #18
0
CSSCombine.prototype._read = function () {
  var thy = this

  if (thy.busy) {
    return
  }
  
  thy.busy = true

  var entrypoint = resolve(thy.file)

  read(entrypoint)
    .on('error', die)
    .pipe(concat(function (content) {
      parse(entrypoint, content, function () {
        thy.push('\n')
        thy.push(null) 
      })
    }))

  function parse (filename, content, callback) {
    if (!content) {
      callback()
      return
    }

    var rules = css
      .parse(content.toString())
      .stylesheet
      .rules

    var i = 0
    var l = rules.length

    if (!l) {
      callback()
      return
    }

    ;(function loop() {
      var rule = rules[i]
      if (rule.type == 'import') {
        var file = extract(rule.import)

        // Allow relative paths
        if (!isURL(file) && /^[^\/\\]/.test(file)) {
          dir = dirname(filename)
          file = normalize(resolve(dir, file))
        }

        // Assume absolute paths use the 
        // working directory as root.
        else if (/^\/|\\/.test(file)) {
          file = normalize(join(process.cwd(), file))
        }

        // Handle malformed, node-style imports
        if (!extname(file)) {
          file = file + '.css'
        }

        read(file)
          .on('error', die)
          .pipe(concat(function (content) {
            parse(file, content, next)
          }))
      }
      else if (rule.declarations && !rule.declarations.length) {
        thy.push(rule.selectors.join(',\n') + ' {}\n')
        next()    
      }
      else {
        thy.push(css.stringify({
          stylesheet: {
            rules: [rule]
          }
        }))
        next()
      }

      function next () {
        ++i < l ?
          loop() :
          callback()
      }
    })()
  }

  function die (error) {
    thy.emit('error', error.message)
  }
}
var hbsfy = require("hbsfy");
var concat = require("concat-stream");
var assert = require("assert");
var fs = require("fs");
var templatePath = __dirname + "/custom_pre_compiler.hbs";

// Subargs are just passed as the second argument
// https://github.com/substack/node-browserify/blob/5cbf55a4397f300df69be574b59f3f30ac01b9c2/bin/advanced.txt#L81-L90
fs.createReadStream(templatePath)
.pipe(hbsfy(templatePath, { precompiler: "ember-template-compiler" }))
.pipe(concat(function(data) {
  assert(
    /hbsfy compiled Handlebars template/.test(data.toString()),
    "The template should be compiled"
  );
}));


Example #20
0
#!/usr/bin/env node

var request = require('request')
var spawn = require('child_process').spawn
var concat = require('concat-stream')

// var url = "http://localhost:5563/collab?username="******"Reporobot doesn't have access to the fork")
    }
  })
}
Example #21
0
//     var server = http.createServer(function (req, res) {
//         if (req.method === 'POST') {
//             req.pipe(concat(function (body) {
//                 var obj = JSON.parse(body);
//                 res.end(Object.keys(obj).join('\n'));
//             }));
//         }
//         else res.end();
//     });
//     server.listen(5000);

// In your adventure you'll only need to buffer input with `concat()` from
// process.stdin.

// Make sure to `npm install concat-stream` in the directory where your solution
// file is located.

	var reverse = require("buffer-reverse");
	// var a = new Buffer('00ff0f', 'hex');
 
	// console.log(reverse(a));



    var concat = require('concat-stream');


    process.stdin.pipe(concat(function( body ){
    	console.log( reverse( body ).toString());

    }));
Example #22
0
var concat = require("concat-stream");
var browserify = require("browserify");
var assert = require("assert");
var vm = require("vm");

var b = browserify(__dirname + "/browsercode.js");
b.transform(require("hbsfy"));

// Browser mock
var context = {
    document: {
        body: {}
    }
};

b.bundle().pipe(concat(function(data) {
    assert(data.length < 35000, "Bundle is too big! Maybe full Handlebars got compiled in?");
    vm.runInNewContext(data.toString(), context);
}));

setTimeout(function() {
    assert.equal(context.document.body.innerHTML.trim(), "<h1>HELLO</h1>");
}, 400);

Browserify.prototype.require = function (file, opts) {
    var self = this;
    
    if (!opts) opts = {};
    var basedir = defined(opts.basedir, process.cwd());
    var expose = opts.expose;
    if (expose === undefined && this._options.exposeAll) {
        expose = true;
    }
    if (expose === true) {
        expose = '/' + path.relative(basedir, file);
    }
    
    if (isStream(file)) {
        self._pending ++;
        var order = self._entryOrder ++;
        file.pipe(concat(function (buf) {
            var filename = opts.file || file.file || path.join(
                basedir,
                '_stream_' + self._entryOrder + '.js'
            );
            var id = file.id || expose || filename;
            if (expose || opts.entry === false) {
                self._expose[id] = filename;
            }
            if (!opts.entry && self._options.exports === undefined) {
                self._bpack.hasExports = true;
            }
            var rec = {
                source: buf.toString('utf8'),
                entry: defined(opts.entry, false),
                file: filename,
                id: id
            };
            if (rec.entry) rec.order = order;
            if (rec.transform === false) rec.transform = false;
            self.pipeline.write(rec);
            
            self._pending --;
            if (self._pending === 0) self.emit('_ready');
        }));
        return this;
    }
    
    var row = typeof file === 'object'
        ? xtend(file, opts)
        : (/^[\/.]/.test(file)
            ? xtend(opts, { file: file })
            : xtend(opts, { id: file })
        )
    ;
    if (!row.id) {
        row.id = expose || file;
    }
    if (expose || !row.entry) {
        this._expose[row.id] = file;
    }
    if (opts.external) return this.external(file, opts);
    if (row.entry === undefined) row.entry = false;
    
    if (!row.entry && this._options.exports === undefined) {
        this._bpack.hasExports = true;
    }
    
    if (row.entry) row.order = self._entryOrder ++;
    if (opts.transform === false) row.transform = false;
    
    this.pipeline.write(row);
    return this;
};
Example #24
0
Browserify.prototype.bundle = function (opts, cb) {
    var self = this;
    if (typeof opts === 'function') {
        cb = opts;
        opts = {};
    }
    if (!opts) opts = {};
    if (opts.insertGlobals === undefined) opts.insertGlobals = false;
    if (opts.detectGlobals === undefined) opts.detectGlobals = true;
    if (opts.ignoreMissing === undefined) opts.ignoreMissing = false;
    if (opts.standalone === undefined) opts.standalone = false;
    
    opts.resolve = self._resolve.bind(self);
    opts.transform = self._transforms;
    opts.noParse = self._noParse;
    opts.transformKey = [ 'browserify', 'transform' ];
    
    var parentFilter = opts.packageFilter;
    opts.packageFilter = function (pkg) {
        if (parentFilter) pkg = parentFilter(pkg);
        return packageFilter(pkg);
    };
    
    if (self._pending) {
        var tr = through();
        self.on('_ready', function () {
            var b = self.bundle(opts, cb);
            if (!cb) b.on('error', tr.emit.bind(tr, 'error'));
            b.pipe(tr);
        });
        return tr;
    }
    
    if (opts.standalone && self._entries.length !== 1) {
        process.nextTick(function () {
            p.emit('error', 'standalone only works with a single entry point');
        });
    }
    
    var prevCache = opts.cache && copy(opts.cache);
    var d = (opts.deps || self.deps.bind(self))(opts);
    var g = opts.detectGlobals || opts.insertGlobals
        ? insertGlobals(self.files, {
            resolve: self._resolve.bind(self),
            always: opts.insertGlobals,
            vars: opts.insertGlobalVars
        })
        : through()
    ;
    var p = self.pack(opts.debug, opts.standalone);
    if (cb) {
        p.on('error', cb);
        p.pipe(concatStream(function (src) { cb(null, src) }));
    }
    g.on('dep', function (dep) { self.emit('dep', dep) });
    
    d.on('error', p.emit.bind(p, 'error'));
    g.on('error', p.emit.bind(p, 'error'));
    d.pipe(through(function (dep) {
        if (self._noParse.indexOf(dep.id) >= 0
        || (prevCache && prevCache[dep.id])) {
            p.write(dep);
        }
        else this.queue(dep)
    })).pipe(g).pipe(p);
    
    return p;
};
Example #25
0
File: rest.js Project: 6a68/dat
 function (cb) {
   request({uri: 'http://localhost:' + dat.options.port + '/api/rows', headers: {'Accept': 'text/csv'}})
     .pipe(csv())
     .pipe(concat(commonFormatTest.bind(null, cb, 'accept:text/csv')))
 },
Example #26
0
'use strict';

var concat = require('concat-stream');

process.stdin.pipe(concat(function(input) {
  console.log(input.toString().split('').reverse().join(''));
}));
Example #27
0
File: rest.js Project: 6a68/dat
 function(cb) {
   request({uri: 'http://localhost:' + dat.options.port + '/api/changes?tail=1&data=true&format=ndjson'})
     .pipe(ldj.parse())
     .pipe(concat(formatTest.bind(null, cb, 'format=ndjson')))
 },
Example #28
0
 stem('authorization', function (res) {
     var html = concat(function (data) {
         document.body.innerHTML = data;
     });
     res.pipe(html);
 }, window, document);
Example #29
0
File: rest.js Project: 6a68/dat
 function(cb) {
   request({uri: 'http://localhost:' + dat.options.port + '/api/changes?tail=1&data=true&format=sse'})
     .pipe(concat(sseTest.bind(null, cb, 'format=sse')))
 },
Example #30
0
 }).on('data', function(file) {
   t.ok(file.contents.pipe, 'output contents are a stream')
   file.contents.pipe(concat(function(upper) {
     t.equal(String(upper), String(contents).toUpperCase())
   }))
 })