Maintainer | i@ak3n.com |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Line-indexed file reader.
Lazily builds the index with the line numbers while reading the file making it possible to rewind to them quickly later.
The indices are stored using a list, with a fixed length capacity, and Array
.
Each new element is added to the list and when the capacity is reached, the list items get flushed
to the array for faster access. The list's capacity can be configured using mkLineIndexedCursorWithCapacity
.
Synopsis
- data LineIndexedCursor = LineIndexedCursor {
- getCurrentLine :: IO (Maybe ByteString)
- getCurrentLineUnsafe :: IO ByteString
- getCurrentLineNumber :: IO Integer
- doFullScan :: IO ()
- goToLine :: Integer -> IO Integer
- getHandle :: Handle
- getCursorState :: IO [Integer]
- mkLineIndexedCursor :: Handle -> IO LineIndexedCursor
- mkLineIndexedCursorWithCapacity :: Handle -> Integer -> IO LineIndexedCursor
Documentation
data LineIndexedCursor #
ADT with methods, hiding the internal state.
getCurrentLine
, getCurrentLineUnsafe
,
doFullScan
, and goToLine
, all throw IOError
.
LineIndexedCursor | |
|
mkLineIndexedCursor :: Handle -> IO LineIndexedCursor #
Builds LineIndexedCursor
. Resets the file handle's ofsset to the beginning.
Use hSetNewlineMode
if you want to configure NewlineMode
.
mkLineIndexedCursorWithCapacity :: Handle -> Integer -> IO LineIndexedCursor #
Same as mkLineIndexedCursor
but allows to configure the list's capacity.