Created
July 15, 2014 14:10
-
-
Save rnewson/e3d6425244528881c2b7 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env escript | |
main(Path) -> | |
{ok, Fd} = file:open(Path, [binary, read, raw]), | |
Count = count_headers(Fd), | |
file:close(Fd), | |
io:format("~s contains ~B headers.~n", [Path, Count]). | |
count_headers(Fd) -> | |
count_headers(Fd, 0, 0). | |
count_headers(Fd, Offset, Acc) -> | |
case file:pread(Fd, Offset, 1) of | |
{ok, <<1>>} -> | |
count_headers(Fd, Offset + 4096, Acc + 1); | |
{ok, <<0>>} -> | |
count_headers(Fd, Offset + 4096, Acc); | |
eof -> | |
Acc | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment