Comparing version
10
index.js
@@ -31,3 +31,9 @@ // Implements http://rfc.zeromq.org/spec:32 | ||
while (byte_nbr < size) { | ||
value = (value * 256) + data[byte_nbr++]; | ||
var characterCode; | ||
if (typeof data == 'string') { | ||
characterCode = data.charCodeAt(byte_nbr++); | ||
} else { | ||
characterCode = data[byte_nbr++]; | ||
} | ||
value = (value * 256) + characterCode; | ||
if ((byte_nbr % 4) == 0) { | ||
@@ -52,3 +58,3 @@ var divisor = 85 * 85 * 85 * 85; | ||
var dest = new Buffer(string.length * 4 / 5); | ||
var dest = new Buffer(string.length * 4 / 5), | ||
byte_nbr = 0, | ||
@@ -55,0 +61,0 @@ char_nbr = 0, |
{ | ||
"name": "z85", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "ZeroMQ Base-85 Encoding", | ||
@@ -28,4 +28,5 @@ "main": "index.js", | ||
"should": "~3.1.2", | ||
"mocha": "~1.17.1" | ||
"mocha": "~1.17.1", | ||
"coveralls": "~2.8.0" | ||
} | ||
} |
[](https://travis-ci.org/msealand/z85.node) | ||
[](https://coveralls.io/r/msealand/z85.node) | ||
@@ -37,2 +38,9 @@ #z85 | ||
$ make test | ||
$ npm test | ||
With code coverage info (using istanbul): | ||
$ npm install -g istanbul | ||
$ make test-cov | ||
_A full code coverage report can be found in coverage/lcov-report/index.html after the tests complete_ |
@@ -7,4 +7,5 @@ var should = require('should'), | ||
it('should encode HelloWorld correctly (http://rfc.zeromq.org/spec:32#toc3)', function() { | ||
var bytes = new Buffer([0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B]); | ||
result = z85.encode(bytes); | ||
var bytes = new Buffer([0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B]), | ||
result = z85.encode(bytes), | ||
decoded = z85.decode(result); | ||
@@ -14,2 +15,3 @@ should.exist(result); | ||
result.should.eql("HelloWorld"); | ||
decoded.should.eql(bytes); | ||
}); | ||
@@ -33,10 +35,24 @@ | ||
result.should.have.length(bytes.length * 5 / 4); | ||
}) | ||
}); | ||
it ('should encode a numeric string correctly', function() { | ||
var input = "1234"; | ||
var expected = "f!$Kw"; | ||
var result = z85.encode(input); | ||
var decoded = z85.decode(result).toString(); | ||
should.exist(result); | ||
result.should.be.a.String; | ||
result.should.have.length(5); | ||
result.should.eql(expected); | ||
decoded.should.eql(input); | ||
}); | ||
it('should encode a random buffer whose length is divisible by 4', function() { | ||
// Test a few of these | ||
for (var i = 1; i <= 100; i++) { | ||
var r = Math.floor(Math.random() * 10) + 1; | ||
var r = Math.floor(Math.random() * 10) + 1, | ||
bytes = utils.randomBuffer(r * 4); | ||
result = z85.encode(bytes); | ||
result = z85.encode(bytes), | ||
decoded = z85.decode(result); | ||
@@ -46,2 +62,3 @@ should.exist(result); | ||
result.should.have.length(bytes.length * 5 / 4); | ||
decoded.should.eql(bytes); | ||
} | ||
@@ -48,0 +65,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9716
13.72%199
11.8%45
18.42%3
50%