Skip to content

Commit

Permalink
remove the cstruct dependency (#137)
Browse files Browse the repository at this point in the history
remove the cstruct dependency

* Minor refactor
* Use write_(sub)string
Then we don't need to do unsafe conversion to bytes.
* The indice start from an offset but still is absolute. We must take in account this detail into our unmarshal_string implementation
* seek_in expects an absolute value where tar wants to move relatively
from the last position - fix the global_Extended_headers_test
* Fix how we parse parameters (and optimise the loop to be tailcall) from
the usage of String.index_from
* Replace Bytes.create by Bytes.make (and initialise buffer with \000)
* Update Tar_gz to manipulate only string & bytes instead of bistring
* upgrade tar-mirage with the new interface
* Upgrade the implementation of tar-eio
* Tar_gz: Remove unused functions from the READER module type
* Fix Tar_mirage
* tar-mirage: undo some cstruct.t -> bytes conversions
* whitespace cleanup

Co-authored-by: Reynir Björnsson <[email protected]>
Co-authored-by: Calascibetta Romain <[email protected]>
Co-authored-by: Kate <[email protected]>
  • Loading branch information
4 people authored Feb 2, 2024
1 parent 4db9b2c commit 9fdff04
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 304 deletions.
20 changes: 10 additions & 10 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
(#119, #120, @MisterDA)
- Support GNU LongLink and LongName. Prior, `Tar.HeaderWriter` and
`Tar.HeaderReader` supported both, but `Tar.Header.Link` only had `LongLink`
and (de)serialized to (from) GNU LongName.
and (de)serialized to (from) GNU LongName (#127)
- Compatibility level when reading / parsing is removed. Only GNU
LongLink/LongName extensions were affected by the compatibility level when
reading.
reading (#127)
- Add module types `Tar.HEADERREADER` and `Tar.HEADERWRITER` describing the
output of `Tar.HeaderReader` and `Tar.HeaderWriter` respectively.
- Types `Tar.READER.t` and `Tar.WRITER.t` are renamed to `io`.
- Add `write_global` function for writing a global PAX extended header.
- Rework IO-specific modules (tar-unix etc.) harmonizing them.
output of `Tar.HeaderReader` and `Tar.HeaderWriter` respectively (#127)
- Types `Tar.READER.t` and `Tar.WRITER.t` are renamed to `io` (#127)
- Add `write_global` function for writing a global PAX extended header (#127)
- Rework IO-specific modules (tar-unix etc.) harmonizing them (#127)
- Avoid exceptions in tar and use result instead. The exceptions
`End_of_stream` and `Checksum_mismatch` are removed.
- Remove the `Tar_cstruct` module as it was unused.
- Remove debug printers.
- Finally remove the unused camlp-streams dependency.
`End_of_stream` and `Checksum_mismatch` are removed (#127)
- Remove the `Tar_cstruct` module as it was unused (#127)
- Remove debug printers (#127)
- Finally remove the unused camlp-streams dependency (#127)

## v2.6.0 (2023-09-07)

Expand Down
19 changes: 5 additions & 14 deletions bin/otar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,13 @@ module Tar_gz = Tar_gz.Make
let return x = x end)
(struct type out_channel = Stdlib.out_channel
type 'a io = 'a
let really_write oc cs =
let str = Cstruct.to_string cs in
let really_write oc str =
output_string oc str end)
(struct type in_channel = Stdlib.in_channel
type 'a io = 'a
let really_read ic cs =
let len = Cstruct.length cs in
let buf = Bytes.create len in
really_input ic buf 0 len ;
Cstruct.blit_from_bytes buf 0 cs 0 len
let skip ic len = really_read ic (Cstruct.create len)
let read ic cs =
let max = Cstruct.length cs in
let buf = Bytes.create max in
let len = input ic buf 0 max in
Cstruct.blit_from_bytes buf 0 cs 0 len ; len end)
let read ic buf =
input ic buf 0 (Bytes.length buf)
end)


let ( / ) = Filename.concat
Expand Down Expand Up @@ -107,7 +98,7 @@ let bytes_to_size ?(decimals = 2) ppf = function

let list filename =
let ic = open_in filename in
let ic = Tar_gz.of_in_channel ~internal:(Cstruct.create 0x1000) ic in
let ic = Tar_gz.of_in_channel ~internal:(De.bigstring_create 0x1000) ic in
let rec go global () = match Tar_gz.HeaderReader.read ~global ic with
| Ok (hdr, global) ->
Format.printf "%s (%s, %a)\n%!"
Expand Down
5 changes: 1 addition & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
(tags ("org:xapi-project" "org:mirage"))
(depends
(ocaml (>= 4.08.0))
(cstruct (>= 6.0.0))
(decompress (>= 1.5.1))
)
)
Expand All @@ -47,8 +46,6 @@
(tags ("org:xapi-project" "org:mirage"))
(depends
(ocaml (>= 4.08.0))
(cstruct (>= 6.0.0))
cstruct-lwt
lwt
(tar (= :version))
)
Expand All @@ -66,7 +63,7 @@
(conflicts (result (< 1.5)))
(depends
(ocaml (>= 4.08.0))
(cstruct (>= 1.9.0))
(cstruct (>= 6.0.0))
(lwt (>= 5.6.0))
(mirage-block (>= 2.0.0))
(mirage-clock (>= 4.0.0))
Expand Down
15 changes: 11 additions & 4 deletions eio/tar_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ end
module Io = struct
type in_channel = Flow.source
type 'a io = 'a
let really_read f b = Flow.read_exact f b
let really_read f b =
let len = Bytes.length b in
let cs = Cstruct.create len in
Flow.read_exact f cs;
Cstruct.blit_to_bytes cs 0 b 0 len
let skip f (n: int) =
let buffer_size = 32768 in
let buffer = Cstruct.create buffer_size in
Expand All @@ -36,15 +40,18 @@ module Io = struct
else
let amount = min n buffer_size in
let block = Cstruct.sub buffer 0 amount in
really_read f block;
Flow.read_exact f block;
loop (n - amount) in
loop n

type out_channel = Flow.sink
let really_write f b = Flow.write f [ b ]
let really_write f str = Flow.write f [ Cstruct.of_string str ]
end

include Io
let really_read = Flow.read_exact
let skip = Io.skip
let really_write f b = Flow.write f [ b ]

module HeaderReader = Tar.HeaderReader(Monad)(Io)
module HeaderWriter = Tar.HeaderWriter(Monad)(Io)

Expand Down
3 changes: 1 addition & 2 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
(name tar)
(modules tar)
(public_name tar)
(wrapped false)
(libraries cstruct))
(wrapped false))

(library
(name tar_gz)
Expand Down
Loading

0 comments on commit 9fdff04

Please sign in to comment.