anchor.diff:  %% 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.
  +%% of binary path segments 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
  
positive.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 = directory_path(DirectoryOpt),
  	case lists:keyfind(file, 1, Opts) of
  		false ->
  			{Filepath, Req2} = cowboy_req:path_info(Req),
  			case check_path(Filepath) of
  				ok ->
  					Filepath2 = join_paths(Directory, Filepath),
  					rest_init(Req2, Opts, Filepath2);
  				error ->
  					{ok, Req2, #state{filepath=error, fileinfo=error,
  						mimetypes=undefined, etag_fun=undefined}}
  			end;
  		{_, FileOpt} ->
  			Filepath = join_paths(Directory, filepath_path(FileOpt)),
  			rest_init(Req, Opts, Filepath)
  	end.
  
  rest_init(Req, Opts, Filepath) ->
  
negative.code: 	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_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([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 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 -> 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">>)
  	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
  