mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 08:13:27 +01:00
24 lines
696 B
TypeScript
24 lines
696 B
TypeScript
import { readBinaryFile, readTextFile } from '@tauri-apps/api/fs';
|
|
import type { HttpResponse } from './models';
|
|
|
|
export async function getResponseBodyText(response: HttpResponse): Promise<string | null> {
|
|
if (response.body) {
|
|
const uint8Array = Uint8Array.from(response.body);
|
|
return new TextDecoder().decode(uint8Array);
|
|
}
|
|
if (response.bodyPath) {
|
|
return await readTextFile(response.bodyPath);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function getResponseBodyBlob(response: HttpResponse): Promise<Uint8Array | null> {
|
|
if (response.body) {
|
|
return Uint8Array.from(response.body);
|
|
}
|
|
if (response.bodyPath) {
|
|
return readBinaryFile(response.bodyPath);
|
|
}
|
|
return null;
|
|
}
|