File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed
Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,14 @@ export class BadgeFileSystemApi {
2020 textEncoder = new TextEncoder ( ) ;
2121 textDecoder = new TextDecoder ( ) ;
2222
23- /** Lists entries in the folder given by `path` */
24- async list ( path : string ) : Promise < FileListing [ ] > {
23+ /**
24+ * Lists entries in the folder given by `path`
25+ * @param path default: `/internal`
26+ */
27+ async list ( path : string = '/internal' ) : Promise < FileListing [ ] > {
28+ if ( path == '' ) {
29+ throw Error ( 'Path must not be empty' ) ;
30+ }
2531 let pathEncoded = this . textEncoder . encode ( path ) ;
2632 let data : ArrayBuffer = await this . transaction ( BadgeUSB . PROTOCOL_COMMAND_FILESYSTEM_LIST , pathEncoded , 4000 ) ;
2733
Original file line number Diff line number Diff line change 33 * @author Reinier van der Leer
44 */
55
6+ import { BadgeUSB , TransactionArgs } from "./badge-usb" ;
67import { BadgeFileSystemApi } from "./api/filesystem" ;
78import { BadgeAppFSApi } from "./api/appfs" ;
89import { BadgeNVSApi } from "./api/nvs" ;
9- import { BadgeUSB } from "./badge-usb" ;
1010
1111export type ProgressCallback = ( status : string , progressPercent : number ) => void ;
1212
@@ -54,15 +54,19 @@ export class BadgeAPI {
5454
5555
5656 /*** Filesystem API ***/
57- public fileSystem = new BadgeFileSystemApi ( this . transaction ) ;
57+ public fileSystem = new BadgeFileSystemApi (
58+ ( ...args : TransactionArgs ) => this . transaction ( ...args ) ,
59+ ) ;
5860
5961 /*** AppFS API ***/
6062 public appFS = new BadgeAppFSApi (
6163 this . fileSystem ,
6264 this . disconnect ,
63- this . transaction ,
65+ ( ... args : TransactionArgs ) => this . transaction ( ... args ) ,
6466 ) ;
6567
6668 /*** NVS API */
67- public nvs = new BadgeNVSApi ( this . transaction ) ;
69+ public nvs = new BadgeNVSApi (
70+ ( ...args : TransactionArgs ) => this . transaction ( ...args ) ,
71+ ) ;
6872}
Original file line number Diff line number Diff line change @@ -471,7 +471,7 @@ export class BadgeUSB {
471471 dataView, identifier, magic,
472472 type : responseType ,
473473 payload : {
474- buffer,
474+ buffer : payload ,
475475 crc : payloadCRC ,
476476 declaredLength : payloadLength ,
477477 } ,
@@ -485,6 +485,8 @@ export class BadgeUSB {
485485 }
486486}
487487
488+ export type TransactionArgs = Parameters < BadgeUSB [ 'transaction' ] > ;
489+
488490class TransactionPromise extends Promise < TransactionResponse > {
489491 resolve : ( value : TransactionResponse | PromiseLike < TransactionResponse > ) => void ;
490492 reject : ( reason : TransactionResponse | Error ) => void ;
You can’t perform that action at this time.
0 commit comments