bangalore-haskell-user-group / functorrent

A bit torrent client
GNU General Public License v3.0
18 stars 9 forks source link

Cleanup bytestring usage #18

Open jaseemabid opened 9 years ago

jaseemabid commented 9 years ago

We use both lazy and strict version interchangeably everywhere. We need to stick to one. I have a feeling that the lazy version might work everywhere.

See http://blog.ezyang.com/2010/08/strings-in-haskell/ for some additional info.

jaseemabid commented 9 years ago

Example:

handShakeMsg :: InfoDict -> String -> ByteString
handShakeMsg m peer_id = let pstrlen = concat $ toChunks $ Bin.encode (19 :: Int8)
                             pstr = pack "BitTorrent protocol"
                             reserved = replicate 8 '\0'
                             infoH = infoHash m
                             peerID = pack peer_id
                         in concat [pstrlen, pstr, reserved, infoH, peerID]

Bin.encode returns the lazy version, and concat . toChunks makes it strict. This might be unnecessary.

Ref: http://stackoverflow.com/questions/1451755/many-types-of-string-bytestring