diff options
Diffstat (limited to 'src/System/Torrent')
-rw-r--r-- | src/System/Torrent/Storage.hs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/System/Torrent/Storage.hs b/src/System/Torrent/Storage.hs index 71e0616b..bf44d7bf 100644 --- a/src/System/Torrent/Storage.hs +++ b/src/System/Torrent/Storage.hs | |||
@@ -25,6 +25,7 @@ module System.Torrent.Storage | |||
25 | , def | 25 | , def |
26 | , open | 26 | , open |
27 | , close | 27 | , close |
28 | , withStorage | ||
28 | 29 | ||
29 | -- * Query | 30 | -- * Query |
30 | , genPieceInfo | 31 | , genPieceInfo |
@@ -58,7 +59,7 @@ data StorageFailure | |||
58 | -- | Piece size do not match with one passed to the 'open' | 59 | -- | Piece size do not match with one passed to the 'open' |
59 | -- function. | 60 | -- function. |
60 | | InvalidSize PieceSize | 61 | | InvalidSize PieceSize |
61 | deriving (Show, Typeable) | 62 | deriving (Show, Eq, Typeable) |
62 | 63 | ||
63 | instance Exception StorageFailure | 64 | instance Exception StorageFailure |
64 | 65 | ||
@@ -76,6 +77,10 @@ open mode s l = Storage mode s <$> mmapFiles mode l | |||
76 | close :: Storage -> IO () | 77 | close :: Storage -> IO () |
77 | close Storage {..} = unmapFiles fileMap | 78 | close Storage {..} = unmapFiles fileMap |
78 | 79 | ||
80 | withStorage :: Mode -> PieceSize -> FileLayout FileSize | ||
81 | -> (Storage -> IO ()) -> IO () | ||
82 | withStorage m s l = bracket (open m s l) close | ||
83 | |||
79 | isValidIx :: PieceIx -> Storage -> Bool | 84 | isValidIx :: PieceIx -> Storage -> Bool |
80 | isValidIx i s = 0 <= i && i < undefined s | 85 | isValidIx i s = 0 <= i && i < undefined s |
81 | 86 | ||