Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Created April 26, 2015 13:31
List to stream interconversion
(* 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);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment