Skip to content

Commit

Permalink
Export readFile() and readBinaryFile() functions from the res module
Browse files Browse the repository at this point in the history
  • Loading branch information
shalithasuranga committed Sep 15, 2024
1 parent 3348793 commit d5968f1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/api/resources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sendMessage } from '../ws/websocket';
import { base64ToBytesArray } from '../helpers';

export function getFiles(): Promise<string[]> {
return sendMessage('resources.getFiles');
Expand All @@ -7,3 +8,19 @@ export function getFiles(): Promise<string[]> {
export function extractFile(path: string, destination: string): Promise<void> {
return sendMessage('resources.extractFile', { path, destination });
};

export function readFile(path: string): Promise<string> {
return sendMessage('resources.readFile', { path });
};

export function readBinaryFile(path: string): Promise<ArrayBuffer> {
return new Promise((resolve: any, reject: any) => {
sendMessage('resources.readBinaryFile', { path })
.then((base64Data: string) => {
resolve(base64ToBytesArray(base64Data));
})
.catch((error: any) => {
reject(error);
});
});
};

0 comments on commit d5968f1

Please sign in to comment.