@@ -757,9 +757,9 @@ var ddb = function(spec, my) {
757757
758758
759759 /**
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
763763 * @throws an error if input object is not compatible
764764 * @return res the converted object
765765 */
@@ -785,13 +785,16 @@ var ddb = function(spec, my) {
785785 }
786786 return isSS ? { "SS" : arr } : { "NS" : arr } ;
787787 }
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 ) ;
789792 }
790793
791794
792795 /**
793796 * converts a DynamoDB compatible JSON object into
794- * a native JSON object
797+ * a native JS object
795798 * @param ddb the ddb JSON object
796799 * @throws an error if input object is not compatible
797800 * @return res the converted object
@@ -812,6 +815,8 @@ var ddb = function(spec, my) {
812815 for ( var j = 0 ; j < ddb [ i ] [ 'NS' ] . length ; j ++ ) {
813816 res [ i ] [ j ] = parseFloat ( ddb [ i ] [ 'NS' ] [ j ] ) ;
814817 }
818+ else if ( ddb [ i ] [ 'B' ] )
819+ res [ i ] = new Buffer ( ddb [ i ] [ 'B' ] , 'base64' ) ;
815820 } else if ( ddb [ i ] [ 'L' ] ) {
816821 res [ i ] = [ ] ;
817822 ddb [ i ] [ 'L' ] . forEach ( function ( item ) {
@@ -822,7 +827,7 @@ var ddb = function(spec, my) {
822827 res [ i ] = objFromDDB ( ddb [ i ] [ 'M' ] ) ;
823828 }
824829 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 ) ;
826831 }
827832 }
828833 return res ;
0 commit comments