@@ -26,19 +26,6 @@ function hex2buffer(hex) {
2626 return buff ;
2727}
2828
29- /**
30- * Helper function to convert the buffer input to a string
31- * @param {Buffer } buf The buffer to convert to a hex-string
32- * @returns {String } The buffer as a hex-string
33- * @api private
34- */
35-
36- function binary2hex ( buf ) {
37- // use buffer built-in function to convert from buffer to hex-string
38- const hex = buf != null && buf . toString ( 'hex' ) ;
39- return hex ;
40- }
41-
4229/**
4330 * Convert a String to Binary
4431 * @param {String } uuidStr The value to process
@@ -67,7 +54,7 @@ function binaryToString(uuidBin) {
6754 // i(hasezoey) dont quite know why, but "uuidBin" may sometimes also be the already processed string
6855 let hex ;
6956 if ( typeof uuidBin !== 'string' && uuidBin != null ) {
70- hex = binary2hex ( uuidBin ) ;
57+ hex = uuidBin . toString ( 'hex' ) ;
7158 const uuidStr = hex . substring ( 0 , 8 ) + '-' + hex . substring ( 8 , 8 + 4 ) + '-' + hex . substring ( 12 , 12 + 4 ) + '-' + hex . substring ( 16 , 16 + 4 ) + '-' + hex . substring ( 20 , 20 + 12 ) ;
7259 return uuidStr ;
7360 }
@@ -90,7 +77,15 @@ function SchemaUUID(key, options) {
9077 if ( value != null && value . $__ != null ) {
9178 return value ;
9279 }
93- return binaryToString ( value ) ;
80+ if ( Buffer . isBuffer ( value ) ) {
81+ return binaryToString ( value ) ;
82+ } else if ( value instanceof Binary ) {
83+ return binaryToString ( value . buffer ) ;
84+ } else if ( utils . isPOJO ( value ) && value . type === 'Buffer' && Array . isArray ( value . data ) ) {
85+ // Cloned buffers look like `{ type: 'Buffer', data: [5, 224, ...] }`
86+ return binaryToString ( Buffer . from ( value . data ) ) ;
87+ }
88+ return value ;
9489 } ) ;
9590}
9691
0 commit comments