From d5968f19dbe9ee28c6d5884c733dbf1ee35b0e19 Mon Sep 17 00:00:00 2001 From: Shalitha Suranga Date: Sun, 15 Sep 2024 13:49:28 +0530 Subject: [PATCH] Export readFile() and readBinaryFile() functions from the res module --- src/api/resources.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/api/resources.ts b/src/api/resources.ts index 0f5ae79..85729af 100644 --- a/src/api/resources.ts +++ b/src/api/resources.ts @@ -1,4 +1,5 @@ import { sendMessage } from '../ws/websocket'; +import { base64ToBytesArray } from '../helpers'; export function getFiles(): Promise { return sendMessage('resources.getFiles'); @@ -7,3 +8,19 @@ export function getFiles(): Promise { export function extractFile(path: string, destination: string): Promise { return sendMessage('resources.extractFile', { path, destination }); }; + +export function readFile(path: string): Promise { + return sendMessage('resources.readFile', { path }); +}; + +export function readBinaryFile(path: string): Promise { + return new Promise((resolve: any, reject: any) => { + sendMessage('resources.readBinaryFile', { path }) + .then((base64Data: string) => { + resolve(base64ToBytesArray(base64Data)); + }) + .catch((error: any) => { + reject(error); + }); + }); +};