]> matita.cs.unibo.it Git - helm.git/commitdiff
- support file:// URL scheme in http_get
authorStefano Zacchiroli <zack@upsilon.cc>
Tue, 7 Jan 2003 17:07:22 +0000 (17:07 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Tue, 7 Jan 2003 17:07:22 +0000 (17:07 +0000)
helm/http_getter/http_getter_misc.ml
helm/http_getter/http_getter_misc.mli

index 880ddd46e4cb71060d28a2932e128d47b98b518a..1ec7101c876b274c06a935248df65a96300e86e0 100644 (file)
@@ -122,7 +122,19 @@ let string_of_proc_status = function
   | Unix.WSTOPPED sg -> sprintf "[Stopped: %d]" sg
 
 let http_get url =
-  try
-    Some (Http_client.Convenience.http_get url)
-  with Http_client.Http_error (code, _) -> None
+  if Pcre.pmatch ~rex:file_scheme_RE url then begin
+      (* file:// URL. Read data from file system *)
+    let fname = Pcre.replace ~rex:file_scheme_RE url in
+    try
+      let size = (Unix.stat fname).Unix.st_size in
+      let buf = String.create size in
+      let ic = open_in fname in
+      really_input ic buf 0 size;
+      close_in ic;
+      Some buf
+    with Unix.Unix_error (Unix.ENOENT, "stat", _) -> None
+  end else  (* other URL, pass it to netclient *)
+    try
+      Some (Http_client.Convenience.http_get url)
+    with Http_client.Http_error (code, _) -> None
 
index d9f8ff873a6e973a96d980e5b9830dc31bbee5dd..94c5dc5a97e2f3b0255a70aa17a0870724f250ea 100644 (file)
@@ -56,6 +56,7 @@ val mkdir: ?parents: bool -> string -> unit
 val string_of_proc_status : Unix.process_status -> string
 
   (** raw HTTP downloader, return Some the contents of downloaded resource or
-  None if an error occured while downlaoding *)
+  None if an error occured while downloading. This function support also
+  "file://" scheme for filesystem resources *)
 val http_get: string -> string option