Comparing file contents in F#

Posted by Bartosz Milewski on Stack Overflow See other posts from Stack Overflow or by Bartosz Milewski
Published on 2010-12-20T20:28:06Z Indexed on 2010/12/21 13:54 UTC
Read the original article Hit count: 305

Filed under:
|
|

I wrote a quick and dirty function to compare file contents (BTW, I have already tested that they are of equal size):

let eqFiles f1 f2 =
  let bytes1 = Seq.ofArray (File.ReadAllBytes f1)
  let bytes2 = Seq.ofArray (File.ReadAllBytes f2)
  let res = Seq.compareWith (fun x y -> (int x) - (int y)) bytes1 bytes2
  res = 0

I'm not happy with reading the whole contents into an array. I'd rather have a lazy sequence of bytes, but I can't find the right API in F#.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about F#