<commit_before>{-# OPTIONS -fno-warn-orphans #-}
{-# LANGUAGE OverloadedStrings #-}
-- | This module provides torrent metainfo serialization.
module Data.Torrent
       ( module Data.Torrent.InfoHash
       , Torrent(..), TorrentInfo(..), TorrentFile(..)
       , fromFile
       ) where

import Control.Applicative
import Control.Monad
import qualified Data.Map as M
import           Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC (pack, unpack)
import           Data.Text (Text)
import Data.BEncode
import Data.Torrent.InfoHash
import Network.URI

type Time = Text

-- TODO more convenient form of torrent info.
-- | Metainfo about particular torrent.
data Torrent = Torrent {
      tInfoHash     :: InfoHash
      -- ^ SHA1 hash of the 'TorrentInfo' of the 'Torrent'.

    , tAnnounce     ::       URI
      -- ^ The URL of the tracker.

    , tAnnounceList :: Maybe [[URI]]
      -- ^ Announce list add multiple tracker support.
      --
      --   BEP 12: <http://www.bittorrent.org/beps/bep_0012.html>

    , tComment      :: Maybe Text
      -- ^ Free-form comments of the author.

    , tCreatedBy    :: Maybe ByteString
      -- ^ Name and version of the program used to create the .torrent.

    , tCreationDate :: Maybe Time
      -- ^ Creation time of the torrent, in standard UNIX epoch.

    , tEncoding     :: Maybe ByteString
      -- ^ String encoding format used to generate the pieces part of
      --   the info dictionary in the .torrent metafile.

    , tInfo         :: TorrentInfo
      -- ^ Info about each content file.

    , tPublisher    :: Maybe URI
      -- ^ Containing the RSA public key of the publisher of the torrent.
      --   Private counterpart of this key that has the authority to allow
      --   new peers onto the swarm.

    , tPublisherURL :: Maybe URI
    , tSignature    :: Maybe ByteString
      -- ^ The RSA signature of the info dictionary (specifically,
      --   the encrypted SHA-1 hash of the info dictionary).
    } deriving Show

-- | Info part of the .torrent file contain info about each content file.
data TorrentInfo =
    SingleFile {
      tLength       :: Int
      -- ^ Length of the file in bytes.

    , tMD5sum       :: Maybe ByteString
      -- ^ 32 character long MD5 sum of the file.
      --   Used by third-party tools, not by bittorrent protocol itself.

    , tName         :: ByteString
      -- ^ Suggested name of the file single file.


<commit_msg>~ fix length type<commit_after>{-# OPTIONS -fno-warn-orphans #-}
{-# LANGUAGE OverloadedStrings #-}
-- | This module provides torrent metainfo serialization.
module Data.Torrent
       ( module Data.Torrent.InfoHash
       , Torrent(..), TorrentInfo(..), TorrentFile(..)
       , fromFile
       ) where

import Control.Applicative
import Control.Monad
import qualified Data.Map as M
import           Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC (pack, unpack)
import           Data.Text (Text)
import Data.BEncode
import Data.Torrent.InfoHash
import Network.URI

type Time = Text

-- TODO more convenient form of torrent info.
-- | Metainfo about particular torrent.
data Torrent = Torrent {
      tInfoHash     :: InfoHash
      -- ^ SHA1 hash of the 'TorrentInfo' of the 'Torrent'.

    , tAnnounce     ::       URI
      -- ^ The URL of the tracker.

    , tAnnounceList :: Maybe [[URI]]
      -- ^ Announce list add multiple tracker support.
      --
      --   BEP 12: <http://www.bittorrent.org/beps/bep_0012.html>

    , tComment      :: Maybe Text
      -- ^ Free-form comments of the author.

    , tCreatedBy    :: Maybe ByteString
      -- ^ Name and version of the program used to create the .torrent.

    , tCreationDate :: Maybe Time
      -- ^ Creation time of the torrent, in standard UNIX epoch.

    , tEncoding     :: Maybe ByteString
      -- ^ String encoding format used to generate the pieces part of
      --   the info dictionary in the .torrent metafile.

    , tInfo         :: TorrentInfo
      -- ^ Info about each content file.

    , tPublisher    :: Maybe URI
      -- ^ Containing the RSA public key of the publisher of the torrent.
      --   Private counterpart of this key that has the authority to allow
      --   new peers onto the swarm.

    , tPublisherURL :: Maybe URI
    , tSignature    :: Maybe ByteString
      -- ^ The RSA signature of the info dictionary (specifically,
      --   the encrypted SHA-1 hash of the info dictionary).
    } deriving Show

-- | Info part of the .torrent file contain info about each content file.
data TorrentInfo =
    SingleFile {
      tLength       :: Integer
      -- ^ Length of the file in bytes.

    , tMD5sum       :: Maybe ByteString
      -- ^ 32 character long MD5 sum of the file.
      --   Used by third-party tools, not by bittorrent protocol itself.

    , tName         :: ByteString
      -- ^ Suggested name of the file single file.



{'fraction_non_alphanumeric': 0.08703481392557023, 'fraction_numerical': 0.005202080832332933, 'mean_word_length': 2.2044871794871796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '766666', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1366, 'n_words': 535}