diff --git a/src/api/filesystem.ts b/src/api/filesystem.ts index 6077a0f..9471487 100644 --- a/src/api/filesystem.ts +++ b/src/api/filesystem.ts @@ -20,8 +20,14 @@ export class BadgeFileSystemApi { textEncoder = new TextEncoder(); textDecoder = new TextDecoder(); - /** Lists entries in the folder given by `path` */ - async list(path: string): Promise { + /** + * Lists entries in the folder given by `path` + * @param path default: `/internal` + */ + async list(path: string = '/internal'): Promise { + if (path == '') { + throw Error('Path must not be empty'); + } let pathEncoded = this.textEncoder.encode(path); let data: ArrayBuffer = await this.transaction(BadgeUSB.PROTOCOL_COMMAND_FILESYSTEM_LIST, pathEncoded, 4000); diff --git a/src/badge-api.ts b/src/badge-api.ts index df504dc..05b8efd 100644 --- a/src/badge-api.ts +++ b/src/badge-api.ts @@ -3,10 +3,10 @@ * @author Reinier van der Leer */ +import { BadgeUSB, TransactionArgs } from "./badge-usb"; import { BadgeFileSystemApi } from "./api/filesystem"; import { BadgeAppFSApi } from "./api/appfs"; import { BadgeNVSApi } from "./api/nvs"; -import { BadgeUSB } from "./badge-usb"; export type ProgressCallback = (status: string, progressPercent: number) => void; @@ -54,15 +54,19 @@ export class BadgeAPI { /*** Filesystem API ***/ - public fileSystem = new BadgeFileSystemApi(this.transaction); + public fileSystem = new BadgeFileSystemApi( + (...args: TransactionArgs) => this.transaction(...args), + ); /*** AppFS API ***/ public appFS = new BadgeAppFSApi( this.fileSystem, this.disconnect, - this.transaction, + (...args: TransactionArgs) => this.transaction(...args), ); /*** NVS API */ - public nvs = new BadgeNVSApi(this.transaction); + public nvs = new BadgeNVSApi( + (...args: TransactionArgs) => this.transaction(...args), + ); } diff --git a/src/badge-usb.ts b/src/badge-usb.ts index e8fc4dd..6b9b6ec 100644 --- a/src/badge-usb.ts +++ b/src/badge-usb.ts @@ -471,7 +471,7 @@ export class BadgeUSB { dataView, identifier, magic, type: responseType, payload: { - buffer, + buffer: payload, crc: payloadCRC, declaredLength: payloadLength, }, @@ -485,6 +485,8 @@ export class BadgeUSB { } } +export type TransactionArgs = Parameters; + class TransactionPromise extends Promise { resolve: (value: TransactionResponse | PromiseLike) => void; reject: (reason: TransactionResponse | Error) => void;