Created
September 9, 2008 00:43
-
-
Save chrisabruce/9583 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
% Save request body to file. | |
save_data(Req, Type) -> | |
Filename = generate_filename(Req, Type), | |
Length = list_to_integer(Req:get_header_value("content-length")), | |
{ok, FileIo} = file:open(Filename, [raw, write]), | |
write_data(FileIo, Req, Length), | |
file:close(FileIo), | |
{ok, Filename}. | |
% Writes Chunked Data to file. | |
write_data(FileIo, Req, Length) when Length > 0 -> | |
case Length of | |
Length when Length < ?CHUNKSIZE -> | |
Chunk = bm:measure("Req:recv", fun() -> Req:recv(Length) end); | |
_ -> | |
Chunk = Req:recv(?CHUNKSIZE) | |
end, | |
file:write(FileIo, Chunk), | |
write_data(FileIo, Req, Length - size(Chunk)); | |
write_data(FileIo, Req, Length) -> | |
ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment