<strong>create_torrent</strong> (file_storage& fs, int piece_size = 0
, int pad_file_limit = -1, int flags = optimize, int alignment = 0x4000);
</pre>
<p>The <ttclass="docutils literal">piece_size</tt> is the size of each piece in bytes. It must
be a multiple of 16 kiB. If a piece size of 0 is specified, a
piece_size will be calculated such that the torrent file is roughly 40 kB.</p>
<p>If a <ttclass="docutils literal">pad_size_limit</tt> is specified (other than -1), any file larger than
the specified number of bytes will be preceeded by a pad file to align it
with the start of a piece. The pad_file_limit is ignored unless the
<ttclass="docutils literal">optimize</tt> flag is passed. Typically it doesn't make sense to set this
any lower than 4kiB.</p>
<p>The overload that takes a <ttclass="docutils literal">torrent_info</tt> object will make a verbatim
copy of its info dictionary (to preserve the info-hash). The copy of
the info dictionary will be used by <aclass="reference external"href="reference-Create_Torrents.html#generate()">create_torrent::generate()</a>. This means
that none of the member functions of <aclass="reference external"href="reference-Create_Torrents.html#create_torrent">create_torrent</a> that affects
the content of the info dictionary (such as <ttclass="docutils literal">set_hash()</tt>), will
have any affect.</p>
<p>The <ttclass="docutils literal">flags</tt> arguments specifies options for the torrent creation. It can
be any combination of the flags defined by <aclass="reference external"href="reference-Create_Torrents.html#flags_t">create_torrent::flags_t</a>.</p>
<p><ttclass="docutils literal">alignment</tt> is used when pad files are enabled. This is the size eligible
files are aligned to. The default is the default bittorrent block size of
16 kiB. It is common to align to the piece size of the torrent.</p>
<aname="generate()"></a></div>
<divclass="section"id="generate">
<h2>generate()</h2>
<preclass="literal-block">
entry <strong>generate</strong> () const;
</pre>
<p>This function will generate the .torrent file as a bencode tree. In order to
generate the flat file, use the <aclass="reference external"href="reference-Bencoding.html#bencode()">bencode()</a> function.</p>
<p>It may be useful to add custom entries to the torrent file before bencoding it
and saving it to disk.</p>
<p>If anything goes wrong during torrent generation, this function will return
an empty <ttclass="docutils literal">entry</tt> structure. You can test for this condition by querying the
type of the entry:</p>
<preclass="literal-block">
file_storage fs;
// add file ...
create_torrent t(fs);
// add trackers and piece hashes ...
e = t.generate();
if (e.type() == entry::undefined_t)
{
// something went wrong
}
</pre>
<p>For instance, you cannot generate a torrent with 0 files in it. If you don't add
any files to the <ttclass="docutils literal">file_storage</tt>, torrent generation will fail.</p>
<td>This will include the file modification time as part of the torrent.
This is not enabled by default, as it might cause problems when you
create a torrent from separate files with the same content, hoping to
yield the same info-hash. If the files have different modification times,
with this option enabled, you would get different info-hashes for the
files.</td>
</tr>
<tr><td>symlinks</td>
<td>8</td>
<td>If this flag is set, files that are symlinks get a symlink attribute
set on them and their data will not be included in the torrent. This
is useful if you need to reconstruct a file hierarchy which contains
symlinks.</td>
</tr>
<tr><td>calculate_file_hashes</td>
<td>16</td>
<td>If this is set, the <aclass="reference external"href="reference-Create_Torrents.html#set_piece_hashes()">set_piece_hashes()</a> function will, as it calculates
the piece hashes, also calculate the file hashes and add those associated
with each file. Note that unless you use the <aclass="reference external"href="reference-Create_Torrents.html#set_piece_hashes()">set_piece_hashes()</a> function,
this flag will have no effect.</td>
</tr>
</tbody>
</table>
<aname="add_files()"></a></div>
<divclass="section"id="add-files">
<h2>add_files()</h2>
<p>Declared in "<aclass="reference external"href="../include/libtorrent/create_torrent.hpp">libtorrent/create_torrent.hpp</a>"</p>
<p>Adds the file specified by <ttclass="docutils literal">path</tt> to the <aclass="reference external"href="reference-Storage.html#file_storage">file_storage</a> object. In case <ttclass="docutils literal">path</tt>
refers to a diretory, files will be added recursively from the directory.</p>
<p>If specified, the predicate <ttclass="docutils literal">p</tt> is called once for every file and directory that
is encountered. files for which <ttclass="docutils literal">p</tt> returns true are added, and directories for
which <ttclass="docutils literal">p</tt> returns true are traversed. <ttclass="docutils literal">p</tt> must have the following signature:</p>
<preclass="literal-block">
bool Pred(std::string const& p);
</pre>
<p>The path that is passed in to the predicate is the full path of the file or
directory. If no predicate is specified, all files are added, and all directories
are traveresed.</p>
<p>The ".." directory is never traversed.</p>
<p>The <ttclass="docutils literal">flags</tt> argument should be the same as the flags passed to the <aclass="reference internal"href="#create-torrent">create_torrent</a>
constructor.</p>
<aname="set_piece_hashes()"></a></div>
<divclass="section"id="set-piece-hashes">
<h2>set_piece_hashes()</h2>
<p>Declared in "<aclass="reference external"href="../include/libtorrent/create_torrent.hpp">libtorrent/create_torrent.hpp</a>"</p>
<preclass="literal-block">
void <strong>set_piece_hashes</strong> (create_torrent& t, std::string const& p