Comparing version 0.0.1 to 0.0.2
@@ -35,12 +35,15 @@ | ||
} | ||
var len = arg.length | ||
if(typeof arg === "string") | ||
var len = Buffer.byteLength(arg); | ||
else | ||
var len = arg.length; | ||
if(this.tail+len >= this.length) | ||
this.resizeBuffer(len) | ||
if(Buffer.isBuffer(arg)){ | ||
arg.copy(this.buffer,this.tail) | ||
}else{ | ||
if(typeof arg === "string") | ||
this.buffer.write(arg,this.tail) | ||
else | ||
this.buffer.write(String(arg),this.tail) | ||
this.buffer.write(arg,this.tail) | ||
} | ||
@@ -47,0 +50,0 @@ this.tail+=len |
@@ -6,3 +6,3 @@ { | ||
"description": "Buffer optimized", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main" : "./flexbuffer", | ||
@@ -9,0 +9,0 @@ "homepage": "https://github.com/mercadolibre/flexbuffer-node", |
@@ -269,4 +269,19 @@ var should = require('should'); | ||
it ("test write caracateres especiales", function (done) { | ||
var str = "\u00bd + \u00bc = \u00be"; | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write(str); | ||
var buffer = new Buffer(str); | ||
flexbuffer.getBuffer().length.should.equal(buffer.length); | ||
// console.log ("flexbuffer.getBufferReference().length: "+flexbuffer.getBufferReference().length); | ||
// console.log ("flexbuffer.getBuffer().length: "+flexbuffer.getBuffer().length); | ||
// console.log ("flexbuffer.getBufferReference().toString().length: "+flexbuffer.getBufferReference().toString('utf8').length); | ||
// console.log ("flexbuffer.getBuffer().toString().length: "+flexbuffer.getBuffer().toString('ascii').length); | ||
// console.log ("str.length: "+str.length); | ||
// console.log ("flexbuffer.getLength: "+flexbuffer.getLength()); | ||
// console.log ("buffer.length: "+buffer.length); | ||
// new String (flexbuffer.getBuffer(), 'utf8').should.equal(str); | ||
done(); | ||
}); | ||
}); |
12173
315