Comparing version 0.9.22 to 0.9.23
@@ -72,10 +72,13 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var StringRW = require('./string_rw'); | ||
var varint = require('./varint'); | ||
var str1 = StringRW(atoms.UInt8, 'utf8'); | ||
var str2 = StringRW(atoms.UInt16BE, 'utf8'); | ||
var strn = StringRW(varint.unsigned, 'utf8'); | ||
module.exports.str1 = str1; | ||
module.exports.str2 = str2; | ||
module.exports.strn = strn; | ||
module.exports.String = StringRW; | ||
module.exports.varint = require('./varint'); | ||
module.exports.varint = varint; | ||
@@ -82,0 +85,0 @@ module.exports.Series = require('./series'); |
{ | ||
"name": "bufrw", | ||
"version": "0.9.22", | ||
"version": "0.9.23", | ||
"description": "Buffer Reading and Writing", | ||
@@ -28,2 +28,3 @@ "keywords": [], | ||
"coveralls": "^2.10.0", | ||
"faucet": "0.0.1", | ||
"istanbul": "^0.3.5", | ||
@@ -45,9 +46,7 @@ "itape": "^1.5.0", | ||
"add-licence": "uber-licence", | ||
"check-cover": "istanbul check-coverage", | ||
"check-licence": "uber-licence --dry", | ||
"check-ls": "npm ls 1>/dev/null", | ||
"cover": "npm run test-cover -s && npm run check-cover -s", | ||
"cover": "istanbul cover --report html --print none test/index.js | faucet && istanbul report text", | ||
"lint": "jshint .", | ||
"test": "npm run check-ls -s && npm run lint -s && npm run cover -s", | ||
"test-cover": "istanbul cover --report html --print detail -- test/index.js", | ||
"test": "npm run check-ls -s && npm run lint -s && npm run cover -s && istanbul check-coverage", | ||
"trace": "itape test/index.js --trace", | ||
@@ -54,0 +53,0 @@ "travis": "npm run cover -s && istanbul report lcov && ((cat coverage/lcov.info | coveralls) || exit 0)", |
@@ -37,8 +37,6 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
self.encoding = encoding || 'utf8'; | ||
// istanbul ignore else | ||
if (self.encoding === 'utf8') { | ||
self.writeInto = self.writeUtf8Into; | ||
self.readFrom = self.readUtf8From; | ||
VariableBufferRW.call(self, sizerw); | ||
if (!self.sizerw.width) { | ||
self.writeInto = self.writeVariableWidthInto; | ||
} | ||
VariableBufferRW.call(self, sizerw); | ||
} | ||
@@ -60,4 +58,3 @@ inherits(StringRW, VariableBufferRW); | ||
// istanbul ignore next | ||
StringRW.prototype.writeInto = function writeInto(str, buffer, offset) { | ||
StringRW.prototype.writeInto = function writeFixedWidthInto(str, buffer, offset) { | ||
var self = this; | ||
@@ -72,2 +69,3 @@ var start = offset + self.sizerw.width; | ||
var res = self.sizerw.writeInto(length, buffer, offset); | ||
// istanbul ignore if | ||
if (res.err) return res; | ||
@@ -77,22 +75,19 @@ return new WriteResult(null, start + length); | ||
StringRW.prototype.writeUtf8Into = function writeInto(str, buffer, offset) { | ||
StringRW.prototype.writeVariableWidthInto = function writeVariableWidthInto(str, buffer, offset) { | ||
var self = this; | ||
var start = offset + self.sizerw.width; | ||
var length = 0; | ||
var size = 0; | ||
if (typeof str === 'string') { | ||
// istanbul ignore else | ||
if (buffer.parent) { | ||
length = buffer.parent.utf8Write(str, buffer.offset + start, buffer.length - start); | ||
} else { | ||
length = buffer.write(str, start, self.encoding); | ||
} | ||
size = Buffer.byteLength(str, self.encoding); | ||
} else if (str !== null && str !== undefined) { | ||
return WriteResult.error(errors.expected(str, 'string, null, or undefined'), offset); | ||
} | ||
var res = self.sizerw.writeInto(length, buffer, offset); | ||
var res = self.sizerw.writeInto(size, buffer, offset); | ||
if (res.err) return res; | ||
return new WriteResult(null, start + length); | ||
offset = res.offset; | ||
if (typeof str === 'string') { | ||
res.offset += buffer.write(str, offset, self.encoding); | ||
} | ||
return res; | ||
}; | ||
// istanbul ignore next | ||
StringRW.prototype.readFrom = function readFrom(buffer, offset) { | ||
@@ -113,22 +108,1 @@ var self = this; | ||
}; | ||
StringRW.prototype.readUtf8From = function readFrom(buffer, offset) { | ||
var self = this; | ||
var res = self.sizerw.readFrom(buffer, offset); | ||
if (res.err) return res; | ||
var length = res.value; | ||
var remain = buffer.length - res.offset; | ||
if (remain < length) { | ||
return ReadResult.shortError(length, remain, offset, res.offset); | ||
} else { | ||
offset = res.offset; | ||
var end = offset + length; | ||
var str = ''; | ||
if (buffer.parent) { | ||
str = buffer.parent.utf8Slice(buffer.offset + offset, buffer.offset + end); | ||
} else { | ||
str = buffer.toString(self.encoding, offset, end); | ||
} | ||
return new ReadResult(null, end, str); | ||
} | ||
}; |
@@ -26,4 +26,7 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var StringRW = require('../string_rw'); | ||
var varint = require('../varint'); | ||
var strn = StringRW(varint.unsigned); | ||
test('Unsigned VarInt', testRW.cases(varint.unsigned, [ | ||
@@ -85,1 +88,68 @@ [0, [0x00]], | ||
])); | ||
var bigTestStr = | ||
'1234567890 1234567890 1234567890 1234567890\n' + | ||
'1234567890 1234567890 1234567890 1234567890\n' + | ||
'1234567890 1234567890 1234567890 1234567890\n' + | ||
'1234567890 1234567890 1234567890 1234567890\n'; | ||
var bigTestBytes = [0x80 | 0x01, 0x30]; // 4 * 44 = 0xb0 | ||
var testSeq = [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30]; | ||
for (var i = 0; i < 4; i++) { | ||
for (var j = 0; j < 4; j++) { | ||
if (j > 0) bigTestBytes.push(0x20); // ' ' | ||
bigTestBytes.push.apply(bigTestBytes, testSeq); // '1234567890' | ||
} // | ||
bigTestBytes.push(0x0a); // '\n' | ||
} | ||
test('strn', testRW.cases(strn, [ | ||
['', [0x00]], | ||
['abc', [0x03, 0x61, 0x62, 0x63]], | ||
[bigTestStr, bigTestBytes], | ||
// undefined value length/write | ||
{ | ||
lengthTest: { | ||
length: 1, | ||
value: undefined | ||
}, | ||
writeTest: { | ||
bytes: [0x00], | ||
value: undefined | ||
} | ||
}, | ||
// null value length/write | ||
{ | ||
lengthTest: { | ||
length: 1, | ||
value: null | ||
}, | ||
writeTest: { | ||
bytes: [0x00], | ||
value: null | ||
} | ||
}, | ||
// invalid value length/write | ||
{ | ||
lengthTest: { | ||
value: {}, | ||
error: { | ||
type: 'bufrw.invalid-argument', | ||
name: 'BufrwInvalidArgumentError', | ||
message: 'invalid argument, expected string, null, or undefined' | ||
} | ||
}, | ||
writeTest: { | ||
value: {}, | ||
error: { | ||
type: 'bufrw.invalid-argument', | ||
name: 'BufrwInvalidArgumentError', | ||
message: 'invalid argument, expected string, null, or undefined' | ||
} | ||
} | ||
} | ||
])); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170642
4278
9