My own corner of monopam
2
fork

Configure Feed

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

ocaml-tar: rewrite README examples against the actual Tar_eio API

Several signatures had drifted: [Tar_eio.extract] takes a [src] union
([Flow] or [File]) and a positional [dst], not [~src ~dst]; [v] is
the inverse of extract and takes [~src:dst-path]; [fold]'s callback
is [?global -> header -> 'acc -> ('acc, _, t) Tar.t] (returning a
[Tar.t], not a plain value); [Tar_gz.decode] doesn't exist (the API
is [Tar_gz.in_gzipped] / [out_gzipped]). Wrap each block as a
function ([extract ()] / [create ()] / [list_entries ()]), point
the gzip section at [Tar_gz] without inventing a [decode] symbol,
add [eio.core] / [fmt] mdx libraries.

+16 -27
+15 -26
ocaml-tar/README.md
··· 34 34 ### Extract a tar archive 35 35 36 36 ```ocaml 37 - let () = 37 + let extract () = 38 38 Eio_main.run @@ fun env -> 39 39 Eio.Switch.run @@ fun sw -> 40 - let src = Eio.Path.open_in ~sw Eio.Path.(env#fs / "archive.tar") in 41 - Tar_eio.extract ~src ~dst:Eio.Path.(env#fs / "output/") 40 + let flow = Eio.Path.open_in ~sw Eio.Path.(env#fs / "archive.tar") in 41 + Tar_eio.extract (Tar_eio.Flow flow) Eio.Path.(env#fs / "output/") 42 42 ``` 43 43 44 44 ### Create a tar archive 45 45 46 46 ```ocaml 47 - let () = 47 + let create () = 48 48 Eio_main.run @@ fun env -> 49 49 Eio.Switch.run @@ fun sw -> 50 50 let sink = 51 51 Eio.Path.open_out ~sw ~create:(`Or_truncate 0o644) 52 52 Eio.Path.(env#fs / "output.tar") 53 53 in 54 - let readme = Eio.Path.(env#fs / "README.md") in 55 - Tar_eio.append_file (sink :> Eio.Flow.sink) 56 - ~level:Tar.Header.Posix 57 - ~header:(Tar_eio.header_of_file ~level:Tar.Header.Posix readme) 58 - readme; 59 - Tar_eio.write_end (sink :> Eio.Flow.sink) 54 + Tar_eio.v ~src:Eio.Path.(env#fs / "input/") sink 60 55 ``` 61 56 62 57 ### Fold over entries 63 58 64 59 ```ocaml 65 - let () = 60 + let list_entries () = 66 61 Eio_main.run @@ fun env -> 67 62 Eio.Switch.run @@ fun sw -> 68 - let src = Eio.Path.open_in ~sw Eio.Path.(env#fs / "archive.tar") in 63 + let flow = Eio.Path.open_in ~sw Eio.Path.(env#fs / "archive.tar") in 69 64 Tar_eio.fold 70 - (fun acc hdr data -> 71 - Printf.printf "%s (%d bytes)\n" hdr.Tar.Header.file_name 72 - (Bytes.Reader.length data); 73 - acc) 74 - src () 65 + (fun ?global:_ hdr acc -> 66 + Fmt.pr "%s (%Ld bytes)@." hdr.Tar.Header.file_name 67 + hdr.Tar.Header.file_size; 68 + Tar.return (Ok (acc + 1))) 69 + (Tar_eio.Flow flow) 0 75 70 ``` 76 71 77 72 ### Gzip support 78 73 79 - The `Tar_gz` module handles `.tar.gz` (gzip-compressed tar) archives: 80 - 81 - ```ocaml 82 - (* Decode from a bytesrw reader *) 83 - let () = 84 - match Tar_gz.decode reader with 85 - | Ok entries -> Seq.iter (fun _ -> ()) entries 86 - | Error msg -> failwith msg 87 - ``` 74 + The `Tar_gz` module handles `.tar.gz` (gzip-compressed tar) archives by 75 + wrapping any `Tar.t` action with `in_gzipped` / `out_gzipped`. See 76 + [Tar_gz] for the streaming API on top of [bytesrw]. 88 77 89 78 ## Core Design 90 79
+1 -1
ocaml-tar/dune
··· 4 4 5 5 (mdx 6 6 (files README.md) 7 - (libraries nox-tar nox-tar-eio nox-tar.gz eio_main eio eio.unix)) 7 + (libraries nox-tar nox-tar-eio nox-tar.gz eio_main eio eio.core eio.unix fmt))