Concat buffer correctly.
JavaScript
Switch branches/tags
Nothing to show
Pull request Compare This branch is 20 commits behind JacksonTian:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
bufferhelper.js
package.json

README.md

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);