|
1 | | -@@ -1,26 +1,23 @@ |
| 1 | +@@ -1,28 +1,24 @@ |
2 | 2 | import argv |
3 | 3 | import file_streams/read_stream |
4 | | - import gleam/bit_array |
5 | 4 | import gleam/int.{to_string} |
6 | 5 | import gleam/io |
7 | | - import gleam/list.{each} |
8 | 6 |
|
9 | 7 | pub fn main() { |
10 | 8 | - // You can use print statements as follows for debugging, they'll be visible when running tests. |
11 | 9 | - io.println("Logs from your program will appear here!") |
| 10 | +- |
12 | 11 | let args = argv.load().arguments |
| 12 | + |
13 | 13 | - // Uncomment this to pass the first stage |
14 | 14 | - // case args { |
15 | 15 | - // [database_file_path, ".dbinfo", ..] -> { |
16 | 16 | - // let assert Ok(rs) = read_stream.open(database_file_path) |
17 | | -- // let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16) |
18 | | -- // let assert Ok(int_value) = read_stream.read_int16_be(rs) |
| 17 | +- // // Get a file handle to the database file, and skip the first 16 bytes |
| 18 | +- // let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16) |
| 19 | +- // // The next 2 bytes hold the page size in big-endian format |
| 20 | +- // let assert Ok(page_size) = read_stream.read_int16_be(rs) |
19 | 21 | - // |
20 | 22 | - // io.print("database page size: ") |
21 | | -- // io.println(to_string(int_value)) |
| 23 | +- // io.println(to_string(page_size)) |
22 | 24 | - // } |
23 | 25 | - // _ -> { |
24 | | -- // io.println("No match") |
| 26 | +- // io.println("Unknown command") |
25 | 27 | - // } |
26 | 28 | - // } |
27 | 29 | + case args { |
28 | 30 | + [database_file_path, ".dbinfo", ..] -> { |
29 | 31 | + let assert Ok(rs) = read_stream.open(database_file_path) |
30 | | -+ let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16) |
31 | | -+ let assert Ok(int_value) = read_stream.read_int16_be(rs) |
| 32 | ++ // Get a file handle to the database file, and skip the first 16 bytes |
| 33 | ++ let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16) |
| 34 | ++ // The next 2 bytes hold the page size in big-endian format |
| 35 | ++ let assert Ok(page_size) = read_stream.read_int16_be(rs) |
32 | 36 | + |
33 | 37 | + io.print("database page size: ") |
34 | | -+ io.println(to_string(int_value)) |
| 38 | ++ io.println(to_string(page_size)) |
35 | 39 | + } |
36 | 40 | + _ -> { |
37 | | -+ io.println("No match") |
| 41 | ++ io.println("Unknown command") |
38 | 42 | + } |
39 | 43 | + } |
40 | 44 | } |
0 commit comments