123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108typet={mutablei_s:bytes;mutablei_pos:int;mutablei_len:int;mutablei_offs:int;mutablei_max_len:int;i_refill:(t->int->unit);i_shared:Bi_share.Rd.tbl;}exceptionEnd_of_inputlettry_prereadibn=ifib.i_len-ib.i_pos<nthen(ib.i_refillibn;min(ib.i_len-ib.i_pos)n)elsenletreadibn=letpos=ib.i_posinifib.i_len-pos>=nthen(ib.i_pos<-pos+n;pos)elseiftry_prereadibn>=nthenletpos=ib.i_posinib.i_pos<-ib.i_pos+n;poselseraiseEnd_of_inputletread_charib=letpos=ib.i_posinifib.i_len-pos>0then(letc=Bytes.unsafe_getib.i_sposinib.i_pos<-pos+1;c)elseiftry_prereadib1>0thenletpos=ib.i_posinletc=Bytes.unsafe_getib.i_sposinib.i_pos<-pos+1;celseraiseEnd_of_inputletpeekib=letpos=ib.i_posinifib.i_len-pos>0then(Bytes.unsafe_getib.i_spos)elseiftry_prereadib1>0thenBytes.unsafe_getib.i_sib.i_poselseraiseEnd_of_inputletfrom_bytes?(pos=0)?(shrlen=16)s={i_s=s;i_pos=pos;i_len=Bytes.lengths;i_offs=-pos;i_max_len=Bytes.lengths;i_refill=(funibn->());i_shared=Bi_share.Rd.createshrlen;}letfrom_string?pos?shrlens=from_bytes?pos?shrlen(Bytes.of_strings)(*
Like Pervasives.really_input but returns the number of bytes
read instead of raising End_of_file when the end of file is reached.
*)letrecnot_really_inputicsposlenaccu=letn=inputicsposleninifn<len&&n>0thennot_really_inputics(pos+n)(len-n)(accu+n)elseaccu+nletrefill_from_channelicibn=ifn>ib.i_max_lentheninvalid_arg"Bi_inbuf.refill_from_channel"else(letrem_len=ib.i_len-ib.i_posinifrem_len<nthenlets=ib.i_sinBytes.blitsib.i_poss0rem_len;letto_read=n-rem_leninletreally_read=not_really_inputicsrem_lento_read0inib.i_offs<-ib.i_offs+ib.i_pos;ib.i_pos<-0;ib.i_len<-rem_len+really_read)letfrom_channel?(len=4096)?(shrlen=16)ic={i_s=Bytes.createlen;i_pos=0;i_len=0;i_offs=0;i_max_len=len;i_refill=refill_from_channelic;i_shared=Bi_share.Rd.createshrlen;}