- (match enc with
- | Enc_normal ->
- (* required format is normal, cached version is gzipped *)
- gunzip (* gunzip to tmp *)
- ~output:tmp ~keep:true (basename ^ ".gz");
- return_file ~fname:tmp ~contype ~patch_fun outchan;
- | Enc_gzipped ->
- (* required format is gzipped, cached version is normal *)
- gzip ~output:tmp ~keep:true basename; (* gzip to tmp *)
- return_file
- ~fname:tmp ~contype ~contenc:"x-gzip"
- ~patch_fun ~gunzip:true
- outchan);
- Sys.remove tmp
- | Some (fname, Enc_normal) -> (* short circuit available, use it! *)
- debug_print "Using short circuit (encoding = normal)";
- return_file ~fname ~contype ~patch_fun outchan;
- Sys.remove fname
- | Some (fname, Enc_gzipped) -> (* short circuit available, use it! *)
- debug_print "Using short circuit (encoding = gzipped)";
- return_file
- ~fname ~contype ~contenc:"x-gzip" ~patch_fun ~gunzip:true outchan;
- Sys.remove fname)
+ finally (fun () -> Sys.remove tmp) (lazy (
+ (match enc with
+ | `Normal ->
+ (* required format is normal, cached version is gzipped *)
+ gunzip (* gunzip to tmp *)
+ ~output:tmp ~keep:true (basename ^ ".gz");
+ return_file ~via_http ~fname:tmp ~contype ~patch_fun outchan;
+ | `Gzipped ->
+ (* required format is gzipped, cached version is normal *)
+ gzip ~output:tmp ~keep:true basename; (* gzip to tmp *)
+ return_file
+ ~via_http ~fname:tmp ~contype ~contenc:"x-gzip"
+ ~patch_fun ~gunzip:true
+ outchan)
+ ))
+ | Some (fname, `Normal) -> (* short circuit available, use it! *)
+ Http_getter_logger.log ~level:2
+ "Using short circuit (encoding = normal)";
+ finally (fun () -> Sys.remove fname) (lazy (
+ return_file ~via_http ~fname ~contype ~patch_fun outchan
+ ))
+ | Some (fname, `Gzipped) -> (* short circuit available, use it! *)
+ Http_getter_logger.log ~level:2
+ "Using short circuit (encoding = gzipped)";
+ finally (fun () -> Sys.remove fname) (lazy (
+ return_file ~via_http ~fname ~contype ~contenc:"x-gzip" ~patch_fun
+ ~gunzip:true outchan
+ )))