-
Notifications
You must be signed in to change notification settings - Fork 292
Add binary xapi_gzip for testing Xapi_compression #4685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
(* | ||
* Copyright (C) Citrix Systems Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
(* This is a minimal test CLI to exercise gzip for compression and | ||
uncompression using the Gzip module; which in turn spawns a process via | ||
Forkexecd *) | ||
|
||
module C = Cmdliner | ||
|
||
module Gzip = Xapi_compression.Make (struct let executable = "/bin/gzip" end) | ||
|
||
let help = | ||
[ | ||
`P "These options are common to all commands." | ||
; `S "MORE HELP" | ||
; `P "Use `$(mname) $(i,COMMAND) --help' for help on a single command." | ||
] | ||
|
||
(** copy bytes from file descriptor [src] to [dst] *) | ||
let copy ~src ~dst = | ||
let size = 1024 * 64 in | ||
let buffer = Bytes.create size in | ||
let rec loop () = | ||
match Unix.read src buffer 0 size with | ||
| 0 -> | ||
() | ||
| n -> | ||
ignore (Unix.write dst buffer 0 n) ; | ||
loop () | ||
in | ||
loop () | ||
|
||
let gzip ~src ~dst = Gzip.compress dst (fun dst -> copy ~src ~dst) | ||
|
||
let gunzip ~src ~dst = Gzip.decompress_passive src (fun src -> copy ~src ~dst) | ||
|
||
let compress uncomp = | ||
match uncomp with | ||
| false -> | ||
gzip ~src:Unix.stdin ~dst:Unix.stdout | ||
| true -> | ||
gunzip ~src:Unix.stdin ~dst:Unix.stdout | ||
|
||
let decompress = | ||
let doc = "Decompress." in | ||
C.Arg.( | ||
value | ||
& flag | ||
& info ["decompress"; "uncompress"; "d"] ~docv:"DECOMPRESS" ~doc | ||
) | ||
|
||
let main = | ||
let doc = "Test compression and uncompression" in | ||
C.Term.(const compress $ decompress, info "xapi-gzip" ~doc ~man:help) | ||
|
||
let () = if !Sys.interactive then () else C.Term.(exit @@ eval main) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting way of making the main module testable from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(* empty *) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a gzip module that does this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but I wanted to avoid the dependency given that it depends on this opam package - that would be circular.