stdcompat__in_channel.ml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102include In_channel (* type t = in_channel type open_flag = Pervasives.open_flag = Open_rdonly | Open_wronly | Open_append | Open_creat | Open_trunc | Open_excl | Open_binary | Open_text | Open_nonblock let stdin = stdin let open_bin = open_in_bin let open_text = open_in let open_gen = open_in_gen let read_and_close channel f = Stdcompat__fun.protect ~finally:(fun () -> close_in_noerr channel) (fun () -> f channel) let with_open_bin filename f = read_and_close (open_bin filename) f let with_open_text filename f = read_and_close (open_text filename) f let with_open_gen flags perm filename f = read_and_close (open_gen flags perm filename) f let seek = LargeFile.seek_in let pos = LargeFile.pos_in let length = LargeFile.in_channel_length let close = close_in let close_noerr = close_in_noerr let input_char ic = try Some (input_char ic) with End_of_file -> None let input_byte ic = try Some (input_byte ic) with End_of_file -> None let input_line ic = try Some (input_line ic) with End_of_file -> None let input = input let really_input ic buf pos len = try really_input ic buf pos len; Some () with End_of_file -> None let really_input_string ic len = try Some (Stdcompat__pervasives.really_input_string ic len) with End_of_file -> None let set_binary_mode = set_binary_mode_in let rec add_channel_to_the_end ~chunk_size buffer channel = if try Stdcompat__buffer.add_channel buffer channel chunk_size; true with End_of_file -> false then add_channel_to_the_end ~chunk_size buffer channel let input_all channel = let buffer_size = in_channel_length channel - pos_in channel in let chunk_size = 65536 in let buffer = Buffer.create buffer_size in add_channel_to_the_end ~chunk_size buffer channel; Buffer.contents buffer *)