Skip to content
Concat buffer correctly and easily.
JavaScript
Latest commit c9a8692 Oct 10, 2015 @JacksonTian Bump 0.2.1
Failed to load latest commit information.
lib caculate length when concat buffer Oct 10, 2015
test
.gitignore
.travis.yml caculate length when concat buffer Oct 10, 2015
MIT_License Add license Jul 3, 2012
README.md Correct example. Feb 17, 2013
index.js Move the file Oct 16, 2012
package.json Bump 0.2.1 Oct 10, 2015

README.md

BufferHelper build status

Why?

Reason of written bufferhelper: 小心data事件里的chunk拼接.

Install it via NPM

npm install bufferhelper

Usage

var http = require('http');
var BufferHelper = require('bufferhelper');

http.createServer(function (request, response) {
  var bufferHelper = new BufferHelper();

  request.on("data", function (chunk) {
    bufferHelper.concat(chunk);
  });
  request.on('end', function () {
    var html = bufferHelper.toBuffer().toString();
    response.writeHead(200);
    response.end(html);
  });

}).listen(8001);

或者更简单:

var http = require('http');
var BufferHelper = require('bufferhelper');

http.createServer(function (request, response) {
  var bufferHelper = new BufferHelper();
  bufferHelper.load(request, function (err, buffer) {
    var html = buffer.toString();
    response.writeHead(200);
    response.end(html);
  });
}).listen(8001);
Something went wrong with that request. Please try again.