@@ -757,9 +757,9 @@ var ddb = function(spec, my) {
757
757
758
758
759
759
/**
760
- * converts a string, string array, number or number array (scalar)
761
- * JSON object to an amazon DynamoDB compatible JSON object
762
- * @param json the JSON scalar object
760
+ * converts a string, string array, number, number array or Buffer (scalar)
761
+ * JS object to an amazon DynamoDB compatible JSON object
762
+ * @param json the JS scalar object
763
763
* @throws an error if input object is not compatible
764
764
* @return res the converted object
765
765
*/
@@ -785,13 +785,16 @@ var ddb = function(spec, my) {
785
785
}
786
786
return isSS ? { "SS" : arr } : { "NS" : arr } ;
787
787
}
788
- throw new Error ( 'Non Compatible Field [not string|number|string array|number array]: ' + value ) ;
788
+ if ( value instanceof Buffer ) {
789
+ return { "B" : value . toString ( 'base64' ) } ;
790
+ }
791
+ throw new Error ( 'Non Compatible Field [not string|number|string array|number array|Buffer]: ' + value ) ;
789
792
}
790
793
791
794
792
795
/**
793
796
* converts a DynamoDB compatible JSON object into
794
- * a native JSON object
797
+ * a native JS object
795
798
* @param ddb the ddb JSON object
796
799
* @throws an error if input object is not compatible
797
800
* @return res the converted object
@@ -812,6 +815,8 @@ var ddb = function(spec, my) {
812
815
for ( var j = 0 ; j < ddb [ i ] [ 'NS' ] . length ; j ++ ) {
813
816
res [ i ] [ j ] = parseFloat ( ddb [ i ] [ 'NS' ] [ j ] ) ;
814
817
}
818
+ } else if ( ddb [ i ] [ 'B' ] ) {
819
+ res [ i ] = new Buffer ( ddb [ i ] [ 'B' ] , 'base64' ) ;
815
820
} else if ( ddb [ i ] [ 'L' ] ) {
816
821
res [ i ] = [ ] ;
817
822
ddb [ i ] [ 'L' ] . forEach ( function ( item ) {
@@ -822,7 +827,7 @@ var ddb = function(spec, my) {
822
827
res [ i ] = objFromDDB ( ddb [ i ] [ 'M' ] ) ;
823
828
}
824
829
else
825
- throw new Error ( 'Non Compatible Field [not "S"|"N"|"NS"|"SS"]: ' + i ) ;
830
+ throw new Error ( 'Non Compatible Field [not "S"|"N"|"NS"|"SS"|"B" ]: ' + i ) ;
826
831
}
827
832
}
828
833
return res ;
0 commit comments