anchor.diff:  -module(etorrent_metainfo).
   -author("Jesper Louis Andersen <jesper.louis.andersen@gmail.com>").
   
  +-include("types.hrl").
  +
   %% API
   -export([get_piece_length/1, get_length/1, get_pieces/1, get_url/1,
            get_infohash/1,
            get_files/1, get_name/1]).
   
   
  -%%====================================================================
  -%% API
  -%%====================================================================
  +%% ====================================================================
   
  -%%--------------------------------------------------------------------
  -%% Function: get_piece_length/1
  -%% Description: Search a torrent file, return the piece length
  -%%--------------------------------------------------------------------
  +% @doc Search a torrent file, return the piece length
  +% @end
  +-spec get_piece_length(bcode()) -> integer().
   get_piece_length(Torrent) ->
       {integer, Size} =
           etorrent_bcoding:search_dict({string, "piece length"},
                                        get_info(Torrent)),
       Size.
   
  -%%--------------------------------------------------------------------
  -%% Function: get_pieces/1
  -%% Description: Search a torrent, return pieces as a list
  -%%--------------------------------------------------------------------
  -get_pieces(Torrent) ->
  -    {string, Ps} = etorrent_bcoding:search_dict({string, "pieces"},
  -                                                get_info(Torrent)),
  -    [list_to_binary(S) || S <- split_into_chunks(Ps)].
  -
  +% @doc Search a torrent for the length field
  +% @end
  +-spec get_length(bcode()) -> integer().
   get_length(Torrent) ->
       case etorrent_bcoding:search_dict({string, "length"},
                                         get_info(Torrent)) of
  
positive.code:             %% Multifile torrent
              sum_files(Torrent)
      end.
  
  get_file_length(File) ->
      {integer, N} = etorrent_bcoding:search_dict({string, "length"},
  
negative.code:                                         get_info(Torrent)),
      lists:sum([get_file_length(F) || F <- Files]).
  
  get_info(Torrent) ->
      etorrent_bcoding:search_dict({string, "info"}, Torrent).
  
  