summaryrefslogtreecommitdiff
path: root/src/System/IO
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-16 07:47:28 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-16 07:47:28 +0400
commit7ad3fd1f6fe3c6719b69f3638542f24b32a3b09c (patch)
tree1af3af8e20c6408109df13745963389fdd08f134 /src/System/IO
parent8101fa8a4286e779c45e17ac2f2b86e91a9f3b0a (diff)
+ Add posix-like file interface.
Diffstat (limited to 'src/System/IO')
-rw-r--r--src/System/IO/MMap/Fixed.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/System/IO/MMap/Fixed.hs b/src/System/IO/MMap/Fixed.hs
index 9d2e354f..df6a6603 100644
--- a/src/System/IO/MMap/Fixed.hs
+++ b/src/System/IO/MMap/Fixed.hs
@@ -46,6 +46,7 @@
46-- > http://hackage.haskell.org/package/mmap 46-- > http://hackage.haskell.org/package/mmap
47-- > man mmap 47-- > man mmap
48-- 48--
49{-# LANGUAGE RecordWildCards #-}
49module System.IO.MMap.Fixed 50module System.IO.MMap.Fixed
50 ( -- * Intervals 51 ( -- * Intervals
51 FixedOffset, FileOffset, FixedInterval, FileInterval 52 FixedOffset, FileOffset, FixedInterval, FileInterval
@@ -58,6 +59,7 @@ module System.IO.MMap.Fixed
58 59
59 -- ** Specialized 'insertTo' 60 -- ** Specialized 'insertTo'
60 , mmapTo, mallocTo 61 , mmapTo, mallocTo
62 , lookupRegion
61 63
62 -- * Query 64 -- * Query
63 , upperAddr 65 , upperAddr
@@ -146,6 +148,13 @@ mallocTo fi s = do
146 fptr <- mallocForeignPtrBytes bsize 148 fptr <- mallocForeignPtrBytes bsize
147 return (insertTo fi (fptr, 0) s) 149 return (insertTo fi (fptr, 0) s)
148 150
151lookupRegion :: FixedOffset -> Fixed -> Maybe B.ByteString
152lookupRegion offset Fixed {..} =
153 case intersecting imap $ IntervalCO offset (succ offset) of
154 [(i, (fptr, off))] -> let s = max 0 $ upperBound i - lowerBound i
155 in Just $ fromForeignPtr fptr off s
156 _ -> Nothing
157
149-- | Note: this is unsafe operation. 158-- | Note: this is unsafe operation.
150viewBytes :: FixedInterval -> Fixed -> Lazy.ByteString 159viewBytes :: FixedInterval -> Fixed -> Lazy.ByteString
151viewBytes fi s = fromChunks $ L.map mk $ (imap s `intersecting` fi) 160viewBytes fi s = fromChunks $ L.map mk $ (imap s `intersecting` fi)