text: /**
  * Copyright 2011 Microsoft Corporation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
  
  /**
   * bufferStream
   * 
   * Creates a writeStream-like object that accumulates results to a buffer
   * 
   */
  
  var createBufferWriteStream = 
    exports.createBufferWriteStream = 
      function(callback) {
    
    var ret = {writeable : true};
    var buffers = [];
    ret.write = function(buffer, encoding) {
      if (typeof buffer === 'string' || (encoding && encoding !== 'binary')) {
        throw new Error('Strings or non-binary encoding are not supported here - use buffers');
      }
      buffers.push(buffer);
      return true;
    };
    
    ret.end = function(buffer) {
      if (buffer) {
        ret.write(buffer);
      }
      var n = buffers.length;
      var size = 0;
      for (var i = 0; i < n; ++i) {
        size += buffers[i].length;
      }
      var buf = new Buffer(size);
      var pos = 0;
      for (i = 0; i < n; ++i) {
        buffers[i].copy(buf, pos);
        pos += buffers[i].length;
      }
      buffers = null; // release unneeded data
      callback(null, buf);
      return true;
    };
    ret.destroy = ret.destroySoon = function() { ret.writeable = false; };
    //Ignore. We don't send any events (like 'drain') to the stream.
    ret.on = function (event, func) {};
    return ret;
  };
  