Created
July 11, 2014 01:30
-
-
Save kai5263499/766b4cbf9f2e621ecfa4 to your computer and use it in GitHub Desktop.
produce a list of tuples which describes the chunks adjusted to the nearest newline
This file contains 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
getChunkDivisions(File, 0, Chunksize, ChunkDivisions) -> | |
[{chunk,0,Chunksize}|ChunkDivisions]; | |
getChunkDivisions(File, Size, Chunksize, ChunkDivisions) -> | |
if | |
Size-Chunksize=<0 -> | |
ComputedChunkEnd = Chunksize-(Chunksize-Size), | |
CorrectedChunkEnd = walkToNextLineBreak(File, ComputedChunkEnd), | |
getChunkDivisions(File, 0, CorrectedChunkEnd, ChunkDivisions); | |
true -> | |
ComputedChunkEnd = Size-Chunksize, | |
CorrectedChunkEnd = walkToNextLineBreak(File, ComputedChunkEnd), | |
getChunkDivisions(File, CorrectedChunkEnd, Chunksize, [{chunk,CorrectedChunkEnd,Size}|ChunkDivisions]) | |
end. | |
walkToNextLineBreak(File,Start) -> | |
file:position(File, Start-1), | |
{ok, Data} = file:read(File, 1024), | |
Start+string:chr(Data, $\n). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment