Created
May 13, 2010 14:41
-
-
Save dgfitch/399896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* In this weird case I need to write a stream but also keep track of how long ago a linefeed was written *) | |
member s.WriteStream (from:Stream) = | |
use reader = new StreamReader(from) | |
let mutable buffer = Array.zeroCreate<char>(BUFFER_LENGTH) | |
let mutable len = 0 | |
while not reader.EndOfStream do | |
len <- reader.ReadBlock(buffer, 0, buffer.Length) | |
s.OutputWriter.Write(buffer, 0, len) | |
(* Now, walk backwards through the buffer looking for linefeeds *) | |
match | |
buffer | |
|> Array.rev | |
|> Array.tryFindIndex ((=) '\n') | |
with | |
| Some index -> s.Column := index - (BUFFER_LENGTH - len) | |
| None -> s.Column := !s.Column + len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment