Skip to content

Commit

Permalink
Download torrent file and verify torrent data
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrov committed Nov 11, 2023
1 parent 8ba95c7 commit 36078ea
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ object TorrentMetadata {
case class Lossless private (
parsed: TorrentMetadata,
raw: Bencode
)
) {
def infoHash: InfoHash = InfoHash(CrossPlatform.sha1(bencode.encode(raw).toByteVector))
}

object Lossless {
def fromBytes(bytes: ByteVector): Either[Throwable, Lossless] =
Expand Down Expand Up @@ -90,4 +92,7 @@ object TorrentFile {
torrentFileFormat.read(bcode)
def fromBytes(bytes: ByteVector): Either[Throwable, TorrentFile] =
bencode.decode(bytes.bits).flatMap(fromBencode)

def toBytes(torrentFile: TorrentFile): ByteVector =
bencode.encode(torrentFileFormat.write(torrentFile).right.get).toByteVector
}
Loading

0 comments on commit 36078ea

Please sign in to comment.