1- const databaseFilePath : string = Deno . args [ 0 ] ;
2- const command : string = Deno . args [ 1 ] ;
1+ import { open } from 'fs/promises' ;
2+ import { constants } from 'fs' ;
3+
4+ const args = process . argv ;
5+ const databaseFilePath : string = args [ 2 ]
6+ const command : string = args [ 3 ] ;
37
48if ( command === ".dbinfo" ) {
5- const databaseFileHandler = await Deno . open ( databaseFilePath , { read : true } ) ;
6- const buffer = new Uint8Array ( 100 ) ;
7- await databaseFileHandler . read ( buffer ) ;
9+ const databaseFileHandler = await open ( databaseFilePath , constants . O_RDONLY ) ;
10+ const buffer : Uint8Array = new Uint8Array ( 100 ) ;
11+ await databaseFileHandler . read ( buffer , 0 , buffer . length , 0 ) ;
812
913 // You can use print statements as follows for debugging, they'll be visible when running tests.
1014 console . log ( "Logs from your program will appear here!" ) ;
@@ -13,7 +17,7 @@ if (command === ".dbinfo") {
1317 // const pageSize = new DataView(buffer.buffer, 0, buffer.byteLength).getUint16(16);
1418 // console.log(`database page size: ${pageSize}`);
1519
16- databaseFileHandler . close ( ) ;
20+ await databaseFileHandler . close ( ) ;
1721} else {
1822 throw new Error ( `Unknown command ${ command } ` ) ;
1923}
0 commit comments