Skip to content

Commit

Permalink
feat: support responseType: 'stream' as ReadableStream (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
okxiaoliang4 committed Sep 19, 2022
1 parent fde55ba commit 5a19f73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export function createFetch (globalOptions: CreateFetchOptions): $Fetch {
const data = await ctx.response.text()
const parseFn = ctx.options.parseResponse || destr
ctx.response._data = parseFn(data)
} else if (responseType === 'stream') {
ctx.response._data = ctx.response.body
} else {
ctx.response._data = await ctx.response[responseType]()
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface ResponseMap {
blob: Blob
text: string
arrayBuffer: ArrayBuffer
stream: ReadableStream<Uint8Array>
}

export type ResponseType = keyof ResponseMap | 'json'
Expand All @@ -52,6 +53,11 @@ export function detectResponseType (_contentType = ''): ResponseType {
return 'json'
}

// TODO
// if (contentType === 'application/octet-stream') {
// return 'stream'
// }

if (textTypes.has(contentType) || contentType.startsWith('text/')) {
return 'text'
}
Expand Down

0 comments on commit 5a19f73

Please sign in to comment.