Block device abstraction for OCaml 5 with Eio direct-style I/O and Bytesrw integration
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: rewrite README example

The Usage example had tokens glued together (`blk Printf.printf`,
`data Block.write`, `Result.get_ok assert`). Rewrite as one clean
file-backed read/write flow.

+19 -19
+19 -19
README.md
··· 26 26 ## Usage 27 27 28 28 ```ocaml 29 - Eio_main.run @@ fun env -> 30 - Eio.Switch.run @@ fun sw -> 31 - 32 - (* Create a file-backed block device *) 33 - let blk = Block.of_file ~sw Eio.Path.(env#fs / "disk.img") ~sector_size:512 ~create:1000L () in 34 - let info = Block.info blk in 35 - Printf.printf "Sectors: %Ld\n" info.sectors; 36 - 37 - (* Write a sector *) 38 - let data = String.make 512 'A' in 39 - Block.write blk 0L data |> Result.get_ok; 40 - 41 - (* Read it back *) 42 - let read = Block.read blk 0L |> Result.get_ok in 43 - assert (data = read); 44 - 45 - (* Add CRC32C integrity checking *) 46 - let safe_blk = Block.with_crc32c blk in 47 - (* Now reads verify checksums, writes compute them *) 29 + let () = 30 + Eio_main.run @@ fun env -> 31 + Eio.Switch.run @@ fun sw -> 32 + (* Create a file-backed block device *) 33 + let blk = 34 + Block.of_file ~sw 35 + Eio.Path.(env#fs / "disk.img") 36 + ~sector_size:512 ~create:1000L () 37 + in 38 + let info = Block.info blk in 39 + Printf.printf "Sectors: %Ld\n" info.sectors; 40 + (* Write a sector, then read it back *) 41 + let data = String.make 512 'A' in 42 + Block.write blk 0L data |> Result.get_ok; 43 + let read = Block.read blk 0L |> Result.get_ok in 44 + assert (data = read); 45 + (* Wrap with CRC32C: reads verify checksums, writes compute them *) 46 + let safe_blk = Block.with_crc32c blk in 47 + Block.close safe_blk 48 48 ``` 49 49 50 50 ## API