1
- async function streamToArrayBuffer ( stream : ReadableStream , streamSize : number ) {
2
- const result = new Uint8Array ( streamSize )
3
- let bytesRead = 0
4
- const reader = stream . getReader ( )
5
- while ( true ) {
6
- const { done, value } = await reader . read ( )
7
- if ( done ) {
8
- break
9
- }
10
- result . set ( value , bytesRead )
11
- bytesRead += value . length
12
- }
13
- return result
14
- }
15
-
16
1
export default eventHandler ( async ( event ) => {
17
2
const { pathname } = await getValidatedRouterParams ( event , z . object ( {
18
3
pathname : z . string ( ) . min ( 1 )
@@ -21,17 +6,12 @@ export default eventHandler(async (event) => {
21
6
22
7
const contentType = getHeader ( event , 'content-type' )
23
8
const contentLength = Number ( getHeader ( event , 'content-length' ) || '0' )
24
- if ( ! query . contentType ) {
25
- query . contentType = contentType
26
- }
27
- if ( ! query . contentLength ) {
28
- query . contentLength = contentLength
29
- }
30
9
31
- // FIXME: find a way to re-stream the readable stream
32
- // const body = getRequestWebStream(event)!
33
- const stream = getRequestWebStream ( event ) !
34
- const body = await streamToArrayBuffer ( stream , contentLength )
10
+ const options = { ...query }
11
+ if ( ! options . contentType ) { options . contentType = contentType }
12
+ if ( ! options . contentLength ) { options . contentLength = contentLength }
13
+
14
+ const body = getRequestWebStream ( event ) !
35
15
36
- return useBlob ( ) . put ( pathname , body , query )
16
+ return useBlob ( ) . put ( pathname , body , options )
37
17
} )
0 commit comments