Skip to content

Commit

Permalink
tweak: Adjust the transform function for binary properties
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Nov 17, 2015
1 parent 3ced29a commit e182b97
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/Transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@ export const DefaultTransforms = {
},
Binary: <PropertyTransform>{
fromDB: value => {
if(!value) return new Buffer(0);
if(value._bsontype === "Binary") {
let binary = new MongoDB.Binary(value);
return binary.read(0, binary.length());
}
if(!value) return null;
if(value._bsontype === "Binary")
return value.buffer;

return new Buffer(0);
return value;
},
toDB: value => {
if(!value) value = new Buffer(0);
else if(Array.isArray(value)) value = new Buffer(value);

if(value && Buffer.isBuffer(value)) return new MongoDB.Binary(value);
if(Buffer.isBuffer(value)) return new MongoDB.Binary(value);
if(Array.isArray(value)) return new MongoDB.Binary(new Buffer(value));
return null;
}
}
Expand Down

0 comments on commit e182b97

Please sign in to comment.