diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-16 07:47:28 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-16 07:47:28 +0400 |
commit | 7ad3fd1f6fe3c6719b69f3638542f24b32a3b09c (patch) | |
tree | 1af3af8e20c6408109df13745963389fdd08f134 /src/System/IO | |
parent | 8101fa8a4286e779c45e17ac2f2b86e91a9f3b0a (diff) |
+ Add posix-like file interface.
Diffstat (limited to 'src/System/IO')
-rw-r--r-- | src/System/IO/MMap/Fixed.hs | 9 |
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 #-} | ||
49 | module System.IO.MMap.Fixed | 50 | module 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 | ||
151 | lookupRegion :: FixedOffset -> Fixed -> Maybe B.ByteString | ||
152 | lookupRegion 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. |
150 | viewBytes :: FixedInterval -> Fixed -> Lazy.ByteString | 159 | viewBytes :: FixedInterval -> Fixed -> Lazy.ByteString |
151 | viewBytes fi s = fromChunks $ L.map mk $ (imap s `intersecting` fi) | 160 | viewBytes fi s = fromChunks $ L.map mk $ (imap s `intersecting` fi) |