File tree 3 files changed +30
-3
lines changed
3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -852,6 +852,7 @@ class Batch {
852
852
853
853
/**
854
854
* Get bucket.
855
+ * @param {Buffer } prefix
855
856
* @returns {Batch }
856
857
*/
857
858
@@ -1907,6 +1908,12 @@ function wrap(resolve, reject) {
1907
1908
} ;
1908
1909
}
1909
1910
1911
+ /**
1912
+ * @param {Buffer|null } prefix
1913
+ * @param {Buffer|null } key
1914
+ * @returns {Buffer? }
1915
+ */
1916
+
1910
1917
function slice ( prefix , key ) {
1911
1918
if ( key == null )
1912
1919
return key ;
@@ -1925,6 +1932,12 @@ function slice(prefix, key) {
1925
1932
return key . slice ( prefix . length ) ;
1926
1933
}
1927
1934
1935
+ /**
1936
+ * @param {Buffer } prefix
1937
+ * @param {Buffer } key
1938
+ * @returns {Buffer }
1939
+ */
1940
+
1928
1941
function concat ( prefix , key ) {
1929
1942
assert ( Buffer . isBuffer ( key ) , 'Key must be a buffer.' ) ;
1930
1943
Original file line number Diff line number Diff line change @@ -575,11 +575,10 @@ class Key {
575
575
*/
576
576
577
577
function makeID ( id ) {
578
- if ( typeof id === 'string' ) {
579
- assert ( id . length === 1 ) ;
578
+ if ( typeof id === 'string' )
580
579
id = Buffer . from ( id , 'ascii' ) ;
581
- }
582
580
581
+ // Number is not supported for multi-byte ids.
583
582
if ( typeof id === 'number' ) {
584
583
assert ( ( id & 0xff ) === id ) ;
585
584
assert ( id !== 0xff ) ;
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ const KEY_IDS = [{
21
21
num : 0x7a , // 'z'
22
22
buf : Buffer . from ( 'z' , 'ascii' ) ,
23
23
expected : Buffer . from ( 'z' , 'ascii' )
24
+ } , {
25
+ str : 'aa' ,
26
+ num : null , // does not support.
27
+ buf : Buffer . from ( 'aa' , 'ascii' ) ,
28
+ expected : Buffer . from ( 'aa' , 'ascii' )
29
+ } , {
30
+ str : 'abcd' ,
31
+ num : null , // does not support.
32
+ buf : Buffer . from ( 'abcd' , 'ascii' ) ,
33
+ expected : Buffer . from ( 'abcd' , 'ascii' )
24
34
} ] ;
25
35
26
36
const KEY_OPS = [ {
@@ -69,6 +79,11 @@ describe('Key', function() {
69
79
} ) ;
70
80
71
81
it ( `should create key for ${ KEY_ID . str } (num)` , ( ) => {
82
+ if ( KEY_ID . num == null ) {
83
+ this . skip ( ) ;
84
+ return ;
85
+ }
86
+
72
87
const key = bdb . key ( KEY_ID . num ) ;
73
88
74
89
assert . bufferEqual ( key . encode ( ) , KEY_ID . expected ) ;
You can’t perform that action at this time.
0 commit comments