| 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
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