restful.js
function jsonEncoder(input, path) {
    var output = new Stream();
    output.readable = true;
    var first = true;
    input.on("data", function (entry) {
      if (path) {
        entry.href = path + entry.name;
        var mime = entry.linkStat ? entry.linkStat.mime : entry.mime;
        if (mime && mime.match(/(directory|folder)$/)) {
          entry.href += "/";
        }
      }
      if (first) {
        output.emit("data", "[\n  " + JSON.stringify(entry));
        first = false;
      } else {
        output.emit("data", ",\n  " + JSON.stringify(entry));
      }
    });
    input.on("end", function () {
      if (first) output.emit("data", "[]");
      else output.emit("data", "\n]");
      output.emit("end");
    });
    if (input.pause) {
      output.pause = function () {
        input.pause();
      };
    }
    if (input.resume) {
      output.resume = function () {
        input.resume();
      };
    }
    return output;
  }
function jsonEncoder(input, path) {
    var output = new Stream();
    output.readable = true;
    var first = true;
    input.on("data", function (entry) {
      if (path) {
        entry.href = path + entry.name;
        var mime = entry.linkStat ? entry.linkStat.mime : entry.mime;
        if (mime && mime.match(/(directory|folder)$/)) {
          entry.href += "/";
        }
      }
      if (first) {
        output.emit("data", "[\n  " + JSON.stringify(entry));
        first = false;
      } else {
        output.emit("data", ",\n  " + JSON.stringify(entry));
      }
    });
    input.on("end", function () {
      if (first) output.emit("data", "[]");
      else output.emit("data", "\n]");
      output.emit("end");
    });
    if (input.pause) {
      output.pause = function () {
        input.pause();
      };
    }
    if (input.resume) {
      output.resume = function () {
        input.resume();
      };
    }
    return output;
  }
function jsonEncoder ( input , path ) { var output = new Stream ( ) ; output . readable = true ; var first = true ; input . on ( "data" , function ( entry ) { if ( path ) { entry . href = path + entry . name ; var mime = entry . linkStat ? entry . linkStat . mime : entry . mime ; if ( mime && mime . match ( / (directory|folder)$ / ) ) { entry . href += "/" ; } } if ( first ) { output . emit ( "data" , "[\n  " + JSON . stringify ( entry ) ) ; first = false ; } else { output . emit ( "data" , ",\n  " + JSON . stringify ( entry ) ) ; } } ) ; input . on ( "end" , function ( ) { if ( first ) output . emit ( "data" , "[]" ) ; else output . emit ( "data" , "\n]" ) ; output . emit ( "end" ) ; } ) ; if ( input . pause ) { output . pause = function ( ) { input . pause ( ) ; } ; } if ( input . resume ) { output . resume = function ( ) { input . resume ( ) ; } ; } return output ; }
Returns a json stream that wraps input object stream
Returns a json stream that wraps input object stream