mirror of
https://github.com/wu736139669/RN_AWord.git
synced 2026-08-07 06:52:32 +00:00
增加node_modules
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0'
|
||||
- '1'
|
||||
- '2'
|
||||
- '3'
|
||||
- '4'
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
Copyright (c) 2011 Jackson Tian
|
||||
http://weibo.com/shyvo
|
||||
|
||||
The MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
BufferHelper [](http://travis-ci.org/JacksonTian/bufferhelper)
|
||||
======
|
||||
## Why?
|
||||
Reason of written `bufferhelper`: [小心data事件里的chunk拼接](http://cnodejs.org/topic/4faf65852e8fb5bc65113403).
|
||||
|
||||
## 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);
|
||||
```
|
||||
+1
@@ -0,0 +1 @@
|
||||
module.exports = require("./lib/bufferhelper.js");
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
var BufferHelper = function () {
|
||||
this.buffers = [];
|
||||
this.size = 0;
|
||||
Object.defineProperty(this, 'length', {
|
||||
get: function () {
|
||||
return this.size;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
BufferHelper.prototype.concat = function (buffer) {
|
||||
this.buffers.push(buffer);
|
||||
this.size += buffer.length;
|
||||
return this;
|
||||
};
|
||||
|
||||
BufferHelper.prototype.empty = function () {
|
||||
this.buffers = [];
|
||||
this.size = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
BufferHelper.prototype.toBuffer = function () {
|
||||
return Buffer.concat(this.buffers, this.size);
|
||||
};
|
||||
|
||||
BufferHelper.prototype.toString = function (encoding) {
|
||||
return this.toBuffer().toString(encoding);
|
||||
};
|
||||
|
||||
BufferHelper.prototype.load = function (stream, callback) {
|
||||
var that = this;
|
||||
stream.on('data', function (trunk) {
|
||||
that.concat(trunk);
|
||||
});
|
||||
stream.on('end', function () {
|
||||
callback(null, that.toBuffer());
|
||||
});
|
||||
stream.once('error', callback);
|
||||
};
|
||||
|
||||
module.exports = BufferHelper;
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"bufferhelper",
|
||||
"/Users/xmfish/Desktop/test/RN_AWord/server"
|
||||
]
|
||||
],
|
||||
"_cnpm_publish_time": 1449543567649,
|
||||
"_from": "bufferhelper@latest",
|
||||
"_id": "bufferhelper@0.2.1",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/bufferhelper",
|
||||
"_nodeVersion": "4.2.2",
|
||||
"_npmUser": {
|
||||
"email": "shyvo1987@gmail.com",
|
||||
"name": "jacksontian"
|
||||
},
|
||||
"_npmVersion": "2.14.7",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "bufferhelper",
|
||||
"raw": "bufferhelper",
|
||||
"rawSpec": "",
|
||||
"scope": null,
|
||||
"spec": "latest",
|
||||
"type": "tag"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/bufferhelper/-/bufferhelper-0.2.1.tgz",
|
||||
"_shasum": "fa74a385724a58e242f04ad6646c2366f83b913e",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "bufferhelper",
|
||||
"_where": "/Users/xmfish/Desktop/test/RN_AWord/server",
|
||||
"author": {
|
||||
"email": "shyvo1987@gmail.com",
|
||||
"name": "Jackson Tian",
|
||||
"url": "http://weibo.com/shyvo"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/JacksonTian/bufferhelper/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Concat buffer correctly.",
|
||||
"devDependencies": {
|
||||
"mocha": "*",
|
||||
"should": "*"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dist": {
|
||||
"noattachment": false,
|
||||
"shasum": "fa74a385724a58e242f04ad6646c2366f83b913e",
|
||||
"size": 2380,
|
||||
"tarball": "http://registry.npm.taobao.org/bufferhelper/download/bufferhelper-0.2.1.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"gitHead": "698a8156cd7c7719ce8ff37075cfbfc9bb16299f",
|
||||
"homepage": "https://github.com/JacksonTian/bufferhelper",
|
||||
"keywords": [
|
||||
"Buffer"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "jacksontian",
|
||||
"email": "shyvo1987@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "bufferhelper",
|
||||
"optionalDependencies": {},
|
||||
"publish_time": 1449543567649,
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/JacksonTian/bufferhelper.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R spec"
|
||||
},
|
||||
"version": "0.2.1"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
var BufferHelper = require('../');
|
||||
var should = require('should');
|
||||
var fs = require('fs');
|
||||
|
||||
describe("BufferHelper", function () {
|
||||
it('new', function () {
|
||||
var bh = new BufferHelper();
|
||||
bh.buffers.should.have.length(0);
|
||||
});
|
||||
|
||||
it('contact', function () {
|
||||
var bh = new BufferHelper();
|
||||
var buffer = new Buffer("呵呵");
|
||||
bh.concat(buffer);
|
||||
bh.length.should.be.equal(6);
|
||||
bh.toBuffer().should.have.length(buffer.length);
|
||||
bh.buffers.should.have.length(1);
|
||||
});
|
||||
|
||||
it('load', function (done) {
|
||||
var bh = new BufferHelper();
|
||||
var reader = fs.createReadStream(__filename);
|
||||
var file = fs.readFileSync(__filename);
|
||||
bh.load(reader, function (err, buf) {
|
||||
should.not.exist(err);
|
||||
buf.should.have.length(file.length);
|
||||
buf.toString().should.be.equal(file.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user