diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Block.hs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/Exchange/Block.hs b/src/Network/BitTorrent/Exchange/Block.hs index e99dd49d..ca635a75 100644 --- a/src/Network/BitTorrent/Exchange/Block.hs +++ b/src/Network/BitTorrent/Exchange/Block.hs | |||
@@ -33,7 +33,7 @@ module Network.BitTorrent.Exchange.Block | |||
33 | 33 | ||
34 | import Control.Applicative | 34 | import Control.Applicative |
35 | import Data.Aeson.TH | 35 | import Data.Aeson.TH |
36 | import qualified Data.ByteString.Lazy as Lazy | 36 | import Data.ByteString.Lazy as BL |
37 | import Data.Char | 37 | import Data.Char |
38 | import Data.List as L | 38 | import Data.List as L |
39 | import Data.Serialize as S | 39 | import Data.Serialize as S |
@@ -138,26 +138,26 @@ data Block payload = Block { | |||
138 | } deriving (Show, Eq, Functor, Typeable) | 138 | } deriving (Show, Eq, Functor, Typeable) |
139 | 139 | ||
140 | -- | Payload is ommitted. | 140 | -- | Payload is ommitted. |
141 | instance Pretty (Block Lazy.ByteString) where | 141 | instance Pretty (Block BL.ByteString) where |
142 | pretty = pretty . blockIx | 142 | pretty = pretty . blockIx |
143 | {-# INLINE pretty #-} | 143 | {-# INLINE pretty #-} |
144 | 144 | ||
145 | -- | Get size of block /payload/ in bytes. | 145 | -- | Get size of block /payload/ in bytes. |
146 | blockSize :: Block Lazy.ByteString -> BlockSize | 146 | blockSize :: Block BL.ByteString -> BlockSize |
147 | blockSize blk = fromIntegral (Lazy.length (blkData blk)) | 147 | blockSize blk = fromIntegral (BL.length (blkData blk)) |
148 | {-# INLINE blockSize #-} | 148 | {-# INLINE blockSize #-} |
149 | 149 | ||
150 | -- | Get block index of a block. | 150 | -- | Get block index of a block. |
151 | blockIx :: Block Lazy.ByteString -> BlockIx | 151 | blockIx :: Block BL.ByteString -> BlockIx |
152 | blockIx = BlockIx <$> blkPiece <*> blkOffset <*> blockSize | 152 | blockIx = BlockIx <$> blkPiece <*> blkOffset <*> blockSize |
153 | 153 | ||
154 | -- | Get location of payload bytes in the torrent content. | 154 | -- | Get location of payload bytes in the torrent content. |
155 | blockRange :: (Num a, Integral a) => PieceSize -> Block Lazy.ByteString -> (a, a) | 155 | blockRange :: (Num a, Integral a) => PieceSize -> Block BL.ByteString -> (a, a) |
156 | blockRange pieceSize = blockIxRange pieceSize . blockIx | 156 | blockRange pieceSize = blockIxRange pieceSize . blockIx |
157 | {-# INLINE blockRange #-} | 157 | {-# INLINE blockRange #-} |
158 | 158 | ||
159 | -- | Test if a block can be safely turned into a piece. | 159 | -- | Test if a block can be safely turned into a piece. |
160 | isPiece :: PieceSize -> Block Lazy.ByteString -> Bool | 160 | isPiece :: PieceSize -> Block BL.ByteString -> Bool |
161 | isPiece pieceLen blk @ (Block i offset _) = | 161 | isPiece pieceLen blk @ (Block i offset _) = |
162 | offset == 0 && blockSize blk == pieceLen && i >= 0 | 162 | offset == 0 && blockSize blk == pieceLen && i >= 0 |
163 | {-# INLINE isPiece #-} | 163 | {-# INLINE isPiece #-} |