@@ -47,7 +47,7 @@ module.exports = function (leveljs, test, testCommon) {
4747 } )
4848 } )
4949
50- test ( 'buffer value' , function ( t ) {
50+ test ( 'put Buffer value, get Buffer value' , function ( t ) {
5151 var level = leveljs ( testCommon . location ( ) )
5252 level . open ( function ( err ) {
5353 t . notOk ( err , 'no error' )
@@ -63,6 +63,88 @@ module.exports = function (leveljs, test, testCommon) {
6363 } )
6464 } )
6565
66+ test ( 'put Buffer value, get Uint8Array value' , function ( t ) {
67+ var level = leveljs ( testCommon . location ( ) )
68+ level . open ( function ( err ) {
69+ t . notOk ( err , 'no error' )
70+ level . put ( 'key' , Buffer . from ( '00ff' , 'hex' ) , function ( err ) {
71+ t . notOk ( err , 'no error' )
72+ level . get ( 'key' , { asBuffer : false } , function ( err , value ) {
73+ t . notOk ( err , 'no error' )
74+ t . notOk ( Buffer . isBuffer ( value ) , 'is not a buffer' )
75+ t . ok ( value instanceof Uint8Array , 'is a Uint8Array' )
76+ t . same ( Buffer . from ( value ) , Buffer . from ( '00ff' , 'hex' ) )
77+ level . close ( t . end . bind ( t ) )
78+ } )
79+ } )
80+ } )
81+ } )
82+
83+ test ( 'put Uint8Array value, get Buffer value' , function ( t ) {
84+ var level = leveljs ( testCommon . location ( ) )
85+ level . open ( function ( err ) {
86+ t . notOk ( err , 'no error' )
87+ level . put ( 'key' , new Uint8Array ( Buffer . from ( '00ff' , 'hex' ) . buffer ) , function ( err ) {
88+ t . notOk ( err , 'no error' )
89+ level . get ( 'key' , function ( err , value ) {
90+ t . notOk ( err , 'no error' )
91+ t . ok ( Buffer . isBuffer ( value ) , 'is buffer' )
92+ t . same ( value , Buffer . from ( '00ff' , 'hex' ) )
93+ level . close ( t . end . bind ( t ) )
94+ } )
95+ } )
96+ } )
97+ } )
98+
99+ test ( 'put Uint8Array value, get Uint8Array value' , function ( t ) {
100+ var level = leveljs ( testCommon . location ( ) )
101+ level . open ( function ( err ) {
102+ t . notOk ( err , 'no error' )
103+ level . put ( 'key' , new Uint8Array ( Buffer . from ( '00ff' , 'hex' ) . buffer ) , function ( err ) {
104+ t . notOk ( err , 'no error' )
105+ level . get ( 'key' , { asBuffer : false } , function ( err , value ) {
106+ t . notOk ( err , 'no error' )
107+ t . notOk ( Buffer . isBuffer ( value ) , 'is not a buffer' )
108+ t . ok ( value instanceof Uint8Array , 'is a Uint8Array' )
109+ t . same ( Buffer . from ( value ) , Buffer . from ( '00ff' , 'hex' ) )
110+ level . close ( t . end . bind ( t ) )
111+ } )
112+ } )
113+ } )
114+ } )
115+
116+ test ( 'put ArrayBuffer value, get Buffer value' , function ( t ) {
117+ var level = leveljs ( testCommon . location ( ) )
118+ level . open ( function ( err ) {
119+ t . notOk ( err , 'no error' )
120+ level . put ( 'key' , Buffer . from ( '00ff' , 'hex' ) . buffer , function ( err ) {
121+ t . notOk ( err , 'no error' )
122+ level . get ( 'key' , function ( err , value ) {
123+ t . notOk ( err , 'no error' )
124+ t . ok ( Buffer . isBuffer ( value ) , 'is buffer' )
125+ t . same ( value , Buffer . from ( '00ff' , 'hex' ) )
126+ level . close ( t . end . bind ( t ) )
127+ } )
128+ } )
129+ } )
130+ } )
131+
132+ test ( 'put ArrayBuffer value, get ArrayBuffer value' , function ( t ) {
133+ var level = leveljs ( testCommon . location ( ) )
134+ level . open ( function ( err ) {
135+ t . notOk ( err , 'no error' )
136+ level . put ( 'key' , Buffer . from ( '00ff' , 'hex' ) . buffer , function ( err ) {
137+ t . notOk ( err , 'no error' )
138+ level . get ( 'key' , { asBuffer : false } , function ( err , value ) {
139+ t . notOk ( err , 'no error' )
140+ t . ok ( value instanceof ArrayBuffer , 'is a ArrayBuffer' )
141+ t . same ( Buffer . from ( value ) , Buffer . from ( '00ff' , 'hex' ) )
142+ level . close ( t . end . bind ( t ) )
143+ } )
144+ } )
145+ } )
146+ } )
147+
66148 // This should be covered by abstract-leveldown tests, but that's
67149 // prevented by process.browser checks (Level/abstract-leveldown#121).
68150 // This test is adapted from memdown.
0 commit comments