Skip to content

Commit

Permalink
fix(connect): add duplex on storage.upload for node compat
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Nov 20, 2023
1 parent 7a2ce78 commit e38c89b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/connect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ import { createReadStream } from 'node:fs'
import { Readable } from 'node:stream'

// Convert the ReadableStream to a NodeJS.ReadableStream
await hyper.storage.download(name).then((res) => Readble.fromWeb(res))
await hyper.storage.download('foo.png')
.then((res) => {
if (!res.ok) throw res
return Readable.fromWeb(res.object)
})

// Or convert to a ReadbleStream from a NodeJS.ReadableStream
await hyper.storage.upload('foo.png', Readable.toWeb(createReadStream('foo.png')))
```
Expand Down
5 changes: 5 additions & 0 deletions packages/connect/deno/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const upload = (name: string, data: ReadableStream) => async (h: HyperReq
// deno-lint-ignore ban-ts-comment
// @ts-ignore
body: data,
/**
* duplex needed for node
* See https://github.com/nodejs/node/issues/46221
*/
duplex: 'half'
})
}

Expand Down

0 comments on commit e38c89b

Please sign in to comment.