anchor.diff:  	end,
   	{{stream, Filesize, Writefile}, Req, State}.
   
  +%% Internal.
  +
   -spec directory_path(dirspec()) -> dirpath().
   directory_path({priv_dir, App, []}) ->
   	priv_dir_path(App);
  -directory_path({priv_dir, App, [H|_]=Path}) when is_integer(H) ->
  +directory_path({priv_dir, App, [H|_]=Path}) when is_binary(H) ->
  +	filename:join(priv_dir_path(App), filename:join(Path));
  +directory_path({priv_dir, App, Path}) ->
   	filename:join(priv_dir_path(App), Path);
  -directory_path({priv_dir, App, [H|_]=Path}) when is_binary(H) ->
  -	filename:join(filename:split(priv_dir_path(App)) ++ Path);
  -directory_path({priv_dir, App, Path}) when is_binary(Path) ->
  -	filename:join(priv_dir_path(App), Path);
  -directory_path(Path) ->
  +directory_path([H|_]=Path) when is_binary(H) ->
  +	filename:join(Path);
  +directory_path([H|_]=Path) when is_integer(H) ->
  +	list_to_binary(Path);
  +directory_path(Path) when is_binary(Path) ->
   	Path.
  -
  -%% @private Ensure that a file path is of the same type as a request path.
  --spec filepath_path(dirpath()) -> Path::[binary()].
  -filepath_path([H|_]=Path) when is_integer(H) ->
  -	filename:split(list_to_binary(Path));
  -filepath_path(Path) when is_binary(Path) ->
  -	filename:split(Path);
  -filepath_path([H|_]=Path) when is_binary(H) ->
  -	Path.
  -
  -%% @private Validate a request path for unsafe characters.
  -%% There is no way to escape special characters in a filesystem path.
  --spec check_path(Path::[binary()]) -> ok | error.
  -check_path([]) -> ok;
  -check_path([<<"">>|_T]) -> error;
  -check_path([<<".">>|_T]) -> error;
  -check_path([<<"..">>|_T]) -> error;
  -check_path([H|T]) ->
  -	case binary:match(H, <<"/">>) of
  -		{_, _} -> error;
  -		nomatch -> check_path(T)
  -	end.
  -
  -%% @private Join the the directory and request paths.
  --spec join_paths(dirpath(), [binary()]) -> binary().
  -join_paths([H|_]=Dirpath, Filepath) when is_integer(H) ->
  -	filename:join(filename:split(Dirpath) ++ Filepath);
  -join_paths([H|_]=Dirpath, Filepath) when is_binary(H) ->
  -	filename:join(Dirpath ++ Filepath);
  -join_paths(Dirpath, Filepath) when is_binary(Dirpath) ->
  -	filename:join([Dirpath] ++ Filepath);
  -join_paths([], Filepath) ->
  -	filename:join(Filepath).
   
   %% @private Return the path to the priv/ directory of an application.
   -spec priv_dir_path(atom()) -> string().
   priv_dir_path(App) ->
   	case code:priv_dir(App) of
   		{error, bad_name} -> priv_dir_mod(App);
  -		Dir -> Dir
  +		Dir -> list_to_binary(Dir)
   	end.
   
   -spec priv_dir_mod(atom()) -> string().
   priv_dir_mod(Mod) ->
   	case code:which(Mod) of
  -		File when not is_list(File) -> "../priv";
  -		File -> filename:join([filename:dirname(File),"../priv"])
  +		File when not is_list(File) -> <<"../priv">>;
  +		File -> filename:join(filename:dirname(File), <<"../priv">>)
   	end.
  +
  +%% @private Ensure that a file path is of the same type as a request path.
  +filepath_path(Path) when is_binary(Path) ->
  +	Path;
  +filepath_path([H|_]=Path) when is_binary(H) ->
  +	filename:join(Path);
  +filepath_path([H|_]=Path) when is_integer(H) ->
  +	list_to_binary(Path).
  +
  +fullpath(Path) when is_binary(Path) ->
  +	fullpath(filename:split(Path), []).
  +fullpath([], Acc) ->
  +	filename:join(lists:reverse(Acc));
  +fullpath([<<".">>|Tail], Acc) ->
  +	fullpath(Tail, Acc);
  +fullpath([<<"..">>|Tail], Acc=[_]) ->
  +	fullpath(Tail, Acc);
  +fullpath([<<"..">>|Tail], [_|Acc]) ->
  +	fullpath(Tail, Acc);
  +fullpath([Segment|Tail], Acc) ->
  +	fullpath(Tail, [Segment|Acc]).
   
   %% @private Use application/octet-stream as the default mimetype.
   %% If a list of extension - mimetype pairs are provided as the mimetypes
  
positive.code: %% under and the path to a directory to read files from. The request path prefix
  %% is defined in the path pattern of the cowboy dispatch rule for the handler.
  %% The request path pattern must end with a `...' token.
  %% The directory path can be set to either an absolute or relative path in the
  %% form of a list or binary string representation of a file system path. A list
  %% of binary path segments, as is used throughout cowboy, is also a valid
  %% directory path.
  %%
  %% The directory path can also be set to a relative path within the `priv/'
  %% directory of an application. This is configured by setting the value of the
  
negative.code: -spec rest_init(Req, list()) -> {ok, Req, #state{}} when Req::cowboy_req:req().
  rest_init(Req, Opts) ->
  	{_, DirectoryOpt} = lists:keyfind(directory, 1, Opts),
  	Directory = fullpath(filename:absname(directory_path(DirectoryOpt))),
  	case lists:keyfind(file, 1, Opts) of
  		false ->
  			{PathInfo, Req2} = cowboy_req:path_info(Req),
  			Filepath = filename:join([Directory|PathInfo]),
  			Len = byte_size(Directory),
  			case fullpath(Filepath) of
  				<< Directory:Len/binary, $/, _/binary >> ->
  					rest_init(Req2, Opts, Filepath);
  				_ ->
  					{ok, Req2, #state{filepath=error, fileinfo=error,
  						mimetypes=undefined, etag_fun=undefined}}
  			end;
  		{_, FileOpt} ->
  			Filepath = filepath_path(FileOpt),
  			Filepath2 = << Directory/binary, $/, Filepath/binary >>,
  			rest_init(Req, Opts, Filepath2)
  	end.
  
  rest_init(Req, Opts, Filepath) ->
  