From 440834ca1304afa98434ccc2b0db82acf6490807 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 22 Nov 2019 13:09:59 -0600 Subject: [PATCH] feat(bin): better human-size display --- src/bin/http_of_dir.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/http_of_dir.ml b/src/bin/http_of_dir.ml index 31e6f2cb..bfb1ec95 100644 --- a/src/bin/http_of_dir.ml +++ b/src/bin/http_of_dir.ml @@ -1,4 +1,3 @@ - module S = Tiny_httpd module Pf = Printf @@ -31,13 +30,16 @@ let contains_dot_dot s = (* Human readable size *) let human_size (x:int) : string = - if x >= 1_000_000 then Printf.sprintf "%d.%dM" (x / 1_000_000) ((x/1000) mod 1_000) + if x >= 1_000_000_000 then Printf.sprintf "%d.%dG" (x / 1_000_000_000) ((x/1_000_000) mod 1_000_000) + else if x >= 1_000_000 then Printf.sprintf "%d.%dM" (x / 1_000_000) ((x/1000) mod 1_000) else if x >= 1_000 then Printf.sprintf "%d.%dk" (x/1000) ((x/100) mod 10) else Printf.sprintf "%db" x let header_html = "Content-Type", "text/html" let (//) = Filename.concat +(* TODO: percent encoding/decoding *) + let html_list_dir ~top ~parent d : string = let entries = Sys.readdir @@ (top // d) in Array.sort compare entries;