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 8035edb commit 7e0958c
Show file tree
Hide file tree
Showing 2 changed files with 13 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
7 changes: 7 additions & 0 deletions packages/connect/deno/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ 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
*/
// deno-lint-ignore ban-ts-comment
// @ts-ignore
duplex: 'half'
})
}

Expand Down

0 comments on commit 7e0958c

Please sign in to comment.