(* read a null terminated stream of bytes into a list *)
let rec streamToList s =
  let b = read s
  match b with
    None  -> []
  | Some(x) -> if x = 0uy then [] else  x::(streamToList s);;
(* write  a list of bytes out as a stream *)
let rec listToStream l s =
   match l with
     [] -> ()
   | x::xs -> (write x s; listToStream xs s);;