/* Copyright 2025, Michele "King_DuckZ" Santullo
* This file is part of ducktorrent.
*
* Ducktorrent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Ducktorrent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ducktorrent. If not, see .
*/
#pragma once
//This file contains higher level helpers that build on top of the parser and
//the visitors in parser.hpp and visitors/find_t_visitor.hpp. It is just here
//for convenience and it is not strictly required to read and parse bencoded
//data.
#include
#include
#include
#include
#include
#include
#include
#include
namespace duck {
struct TorrentValue;
class TorrentRead {
public:
TorrentRead (std::string_view torrent_path, std::filesystem::path workdir);
TorrentRead (const TorrentRead&) = delete;
~TorrentRead() noexcept;
void print (std::ostream& out) const;
std::size_t raw_data_size() const;
const std::vector& parsed_values() const;
std::string_view read_name() const;
std::size_t read_piece_length() const;
std::int_fast32_t read_file_count() const;
std::vector read_file_path(std::size_t index) const;
std::string read_joint_file_path(std::size_t index, char sep) const;
std::size_t read_file_size(std::size_t index) const;
bool read_is_private() const;
std::string_view read_comment() const;
std::string_view read_hashes() const;
std::string_view read_created_by() const;
std::string_view read_announce() const;
std::time_t read_creation_date() const;
private:
const TorrentValue& cached_info_files() const;
std::filesystem::path m_workdir;
std::filesystem::path m_torrent_path;
std::string m_raw_torrent;
std::vector m_parsed_values;
mutable const TorrentValue* m_cached_info_files;
};
std::vector> group_torrent_hashes (std::string_view hashes);
std::vector> group_torrent_hashes (const TorrentRead& torrent);
} //namespace duck