updated more sample code in manual

This commit is contained in:
Arvid Norberg
2005-11-21 22:47:15 +00:00
parent 282b06a9a5
commit 9d12136854
2 changed files with 25 additions and 14 deletions

View File

@@ -2687,7 +2687,6 @@ print information about it to std out:</p>
#include &lt;iostream&gt; #include &lt;iostream&gt;
#include &lt;fstream&gt; #include &lt;fstream&gt;
#include &lt;iterator&gt; #include &lt;iterator&gt;
#include &lt;exception&gt;
#include &lt;iomanip&gt; #include &lt;iomanip&gt;
#include &quot;libtorrent/entry.hpp&quot; #include &quot;libtorrent/entry.hpp&quot;
@@ -2709,27 +2708,33 @@ int main(int argc, char* argv[])
{ {
std::ifstream in(argv[1], std::ios_base::binary); std::ifstream in(argv[1], std::ios_base::binary);
in.unsetf(std::ios_base::skipws); in.unsetf(std::ios_base::skipws);
entry e = bdecode(std::istream_iterator&lt;char&gt;(in) entry e = bdecode(std::istream_iterator&lt;char&gt;(in), std::istream_iterator&lt;char&gt;());
, std::istream_iterator&lt;char&gt;());
std::cout &lt;&lt; &quot;\n\n----- raw info -----\n\n&quot;;
e.print(std::cout);
torrent_info t(e); torrent_info t(e);
// print info about torrent // print info about torrent
std::cout &lt;&lt; &quot;\n\n----- torrent file info -----\n\n&quot;; std::cout &lt;&lt; &quot;\n\n----- torrent file info -----\n\n&quot;;
std::cout &lt;&lt; &quot;trackers:\n&quot;; std::cout &lt;&lt; &quot;trackers:\n&quot;;
for (std::vector&lt;announce_entry&gt;::const_iterator i for (std::vector&lt;announce_entry&gt;::const_iterator i = t.trackers().begin();
= t.trackers().begin(), end(t.trackers().end()); i != end; ++i) i != t.trackers().end(); ++i)
{ {
std::cout &lt;&lt; i-&gt;tier &lt;&lt; &quot;: &quot; &lt;&lt; i-&gt;url &lt;&lt; &quot;\n&quot;; std::cout &lt;&lt; i-&gt;tier &lt;&lt; &quot;: &quot; &lt;&lt; i-&gt;url &lt;&lt; &quot;\n&quot;;
} }
std::cout &lt;&lt; &quot;number of pieces: &quot; &lt;&lt; t.num_pieces() &lt;&lt; &quot;\n&quot;; std::cout &lt;&lt; &quot;number of pieces: &quot; &lt;&lt; t.num_pieces() &lt;&lt; &quot;\n&quot;;
std::cout &lt;&lt; &quot;piece length: &quot; &lt;&lt; t.piece_length() &lt;&lt; &quot;\n&quot;; std::cout &lt;&lt; &quot;piece length: &quot; &lt;&lt; t.piece_length() &lt;&lt; &quot;\n&quot;;
std::cout &lt;&lt; &quot;info hash: &quot; &lt;&lt; t.info_hash() &lt;&lt; &quot;\n&quot;;
std::cout &lt;&lt; &quot;comment: &quot; &lt;&lt; t.comment() &lt;&lt; &quot;\n&quot;;
std::cout &lt;&lt; &quot;created by: &quot; &lt;&lt; t.creator() &lt;&lt; &quot;\n&quot;;
std::cout &lt;&lt; &quot;files:\n&quot;; std::cout &lt;&lt; &quot;files:\n&quot;;
for (torrent_info::file_iterator i = t.begin_files(); for (torrent_info::file_iterator i = t.begin_files();
i != t.end_files(); ++i) i != t.end_files(); ++i)
{ {
std::cout &lt;&lt; &quot; &quot; &lt;&lt; std::setw(11) &lt;&lt; i-&gt;size std::cout &lt;&lt; &quot; &quot; &lt;&lt; std::setw(11) &lt;&lt; i-&gt;size
&lt;&lt; &quot; &quot; &lt;&lt; i-&gt;path &lt;&lt; &quot; &quot; &lt;&lt; i-&gt;filename &lt;&lt; &quot;\n&quot;; &lt;&lt; &quot; &quot; &lt;&lt; i-&gt;path.string() &lt;&lt; &quot;\n&quot;;
} }
} }

View File

@@ -2771,10 +2771,10 @@ dump_torrent
This is an example of a program that will take a torrent-file as a parameter and This is an example of a program that will take a torrent-file as a parameter and
print information about it to std out:: print information about it to std out::
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <iterator> #include <iterator>
#include <exception>
#include <iomanip> #include <iomanip>
#include "libtorrent/entry.hpp" #include "libtorrent/entry.hpp"
@@ -2785,7 +2785,7 @@ print information about it to std out::
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
using namespace libtorrent; using namespace libtorrent;
if (argc != 2) if (argc != 2)
{ {
std::cerr << "usage: dump_torrent torrent-file\n"; std::cerr << "usage: dump_torrent torrent-file\n";
@@ -2796,27 +2796,33 @@ print information about it to std out::
{ {
std::ifstream in(argv[1], std::ios_base::binary); std::ifstream in(argv[1], std::ios_base::binary);
in.unsetf(std::ios_base::skipws); in.unsetf(std::ios_base::skipws);
entry e = bdecode(std::istream_iterator<char>(in) entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
, std::istream_iterator<char>());
torrent_info t(e);
std::cout << "\n\n----- raw info -----\n\n";
e.print(std::cout);
torrent_info t(e);
// print info about torrent // print info about torrent
std::cout << "\n\n----- torrent file info -----\n\n"; std::cout << "\n\n----- torrent file info -----\n\n";
std::cout << "trackers:\n"; std::cout << "trackers:\n";
for (std::vector<announce_entry>::const_iterator i for (std::vector<announce_entry>::const_iterator i = t.trackers().begin();
= t.trackers().begin(), end(t.trackers().end()); i != end; ++i) i != t.trackers().end(); ++i)
{ {
std::cout << i->tier << ": " << i->url << "\n"; std::cout << i->tier << ": " << i->url << "\n";
} }
std::cout << "number of pieces: " << t.num_pieces() << "\n"; std::cout << "number of pieces: " << t.num_pieces() << "\n";
std::cout << "piece length: " << t.piece_length() << "\n"; std::cout << "piece length: " << t.piece_length() << "\n";
std::cout << "info hash: " << t.info_hash() << "\n";
std::cout << "comment: " << t.comment() << "\n";
std::cout << "created by: " << t.creator() << "\n";
std::cout << "files:\n"; std::cout << "files:\n";
for (torrent_info::file_iterator i = t.begin_files(); for (torrent_info::file_iterator i = t.begin_files();
i != t.end_files(); ++i) i != t.end_files(); ++i)
{ {
std::cout << " " << std::setw(11) << i->size std::cout << " " << std::setw(11) << i->size
<< " " << i->path << " " << i->filename << "\n"; << " " << i->path.string() << "\n";
} }
} }