Skip to content

Instantly share code, notes, and snippets.

@chrisabruce
Created September 9, 2008 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisabruce/9583 to your computer and use it in GitHub Desktop.
Save chrisabruce/9583 to your computer and use it in GitHub Desktop.
% 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