@@ -260,6 +260,19 @@ describe("KV API", () => {
260260 expect ( response . status ) . toBe ( 200 ) ;
261261 expect ( await response . text ( ) ) . toBe ( "special-value" ) ;
262262 } ) ;
263+
264+ test ( "returns raw bytes for ArrayBuffer values" , async ( { expect } ) => {
265+ const kv = await mf . getKVNamespace ( "TEST_KV" ) ;
266+ const bytes = Uint8Array . from ( [ 0 , 1 , 2 , 127 , 128 , 254 , 255 ] ) ;
267+ await kv . put ( "binary-get-key" , bytes . buffer ) ;
268+
269+ const response = await mf . dispatchFetch (
270+ `${ BASE_URL } /storage/kv/namespaces/test-kv-id/values/binary-get-key`
271+ ) ;
272+
273+ expect ( response . status ) . toBe ( 200 ) ;
274+ expect ( new Uint8Array ( await response . arrayBuffer ( ) ) ) . toEqual ( bytes ) ;
275+ } ) ;
263276 } ) ;
264277
265278 describe ( "PUT /storage/kv/namespaces/:namespaceId/values/:keyName" , ( ) => {
@@ -316,6 +329,33 @@ describe("KV API", () => {
316329 errors : [ expect . objectContaining ( { code : 10013 } ) ] ,
317330 } ) ;
318331 } ) ;
332+
333+ test ( "writes streamed binary values" , async ( { expect } ) => {
334+ const bytes = Uint8Array . from ( [ 255 , 0 , 10 , 20 , 30 , 200 ] ) ;
335+ const response = await mf . dispatchFetch (
336+ `${ BASE_URL } /storage/kv/namespaces/test-kv-id/values/put-stream-key` ,
337+ {
338+ body : new Blob ( [ bytes ] ) . stream ( ) ,
339+ duplex : "half" ,
340+ headers : {
341+ "Content-Type" : "application/octet-stream" ,
342+ } ,
343+ method : "PUT" ,
344+ }
345+ ) ;
346+
347+ expect ( response . status ) . toBe ( 200 ) ;
348+ expect ( await response . json ( ) ) . toMatchObject ( { success : true } ) ;
349+
350+ const kv = await mf . getKVNamespace ( "TEST_KV" ) ;
351+ const stored = await kv . get ( "put-stream-key" , { type : "arrayBuffer" } ) ;
352+
353+ expect ( stored ) . not . toBeNull ( ) ;
354+ if ( stored === null ) {
355+ throw new Error ( "Expected put-stream-key to be stored in KV" ) ;
356+ }
357+ expect ( new Uint8Array ( stored ) ) . toEqual ( bytes ) ;
358+ } ) ;
319359 } ) ;
320360
321361 describe ( "DELETE /storage/kv/namespaces/:namespaceId/values/:keyName" , ( ) => {
0 commit comments