1

I have a multi-file torrent (3 files). I subscribed to read_piece_alert as explained here.

std::vector<alert*> alerts;
ses.pop_alerts(&alerts);
for (alert* i : alerts) {
        switch (a->type()) {

                case read_piece_alert::alert_type:
                {
                        read_piece_alert* p = (read_piece_alert*)a;
                        if (p->ec) {
                                // read_piece failed
                                break;
                        }
                        // use p
                        break;
                }
                case file_renamed_alert::alert_type:
                {
                        // etc...
                }
        }
}

How can I know to which file the piece belongs in the multi-file torrent?

For example my multi-file torrent has an .AVI, .TXT and .JPG. Is there some kind of index to know to which file the piece actually belongs?

user3606329
  • 2,405
  • 1
  • 16
  • 28

1 Answers1

1

yes. you can map a piece-index into one or more file-indices + offsets with the map_block() function on file_storage. See the documentation.

Arvid
  • 10,915
  • 1
  • 32
  • 40