Do not call toString on buffers
This commit is contained in:
parent
540a3a1f5c
commit
ce27a3660f
|
@ -54,6 +54,7 @@ Object.defineProperties(Change.prototype, {
|
|||
return this._modification;
|
||||
},
|
||||
set: function setModification(val) {
|
||||
var currVal;
|
||||
if (Attribute.isAttribute(val)) {
|
||||
this._modification = val;
|
||||
return;
|
||||
|
@ -79,12 +80,15 @@ Object.defineProperties(Change.prototype, {
|
|||
var k = keys[0];
|
||||
console.log(keys);
|
||||
var _attr = new Attribute({type: k});
|
||||
if (Array.isArray(val[k])) {
|
||||
|
||||
currVal = val[k];
|
||||
if (Array.isArray(currVal)) {
|
||||
val[k].forEach(function (v) {
|
||||
_attr.addValue(v.toString());
|
||||
});
|
||||
} else {
|
||||
_attr.addValue(val[k].toString());
|
||||
var attrVal = Buffer.isBuffer(currVal) ? currVal : currVal.toString();
|
||||
_attr.addValue(attrVal);
|
||||
}
|
||||
this._modification = _attr;
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var test = require('tape').test;
|
||||
|
||||
var fs = require('fs');
|
||||
var asn1 = require('asn1');
|
||||
|
||||
|
||||
|
@ -49,6 +49,27 @@ test('new with args', function (t) {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('new with args and buffer', function (t) {
|
||||
|
||||
|
||||
var img = fs.readFileSync(__dirname + '/imgs/test.jpg');
|
||||
|
||||
var change = new Change({
|
||||
operation: 'add',
|
||||
modification: {
|
||||
thumbnailPhoto: img
|
||||
}
|
||||
});
|
||||
|
||||
t.ok(change);
|
||||
|
||||
t.equal(change.operation, 'add');
|
||||
t.equal(change.modification.type, 'thumbnailPhoto');
|
||||
t.equal(change.modification.vals.length, 1);
|
||||
t.equal(change.modification.buffers[0].compare(img), 0);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('validate fields', function (t) {
|
||||
var c = new Change();
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 740 B |
Loading…
Reference in New Issue