| Safe Haskell | None |
|---|
Database.PureCDB
Contents
Description
A library for reading and writing CDB (Constant Database) files.
CDB files are immutable key-value stores, designed for extremely fast and memory-efficient construction and lookup. They can be as large as 4GB, and at no point in their construction or use must all data be loaded into memory. CDB files can contain multiple values for a given key.
For more information on the CDB file format, please see: http://cr.yp.to/cdb.html
Here's how you make new CDB file:
import qualified Data.ByteString.Char8 as B
import Database.PureCDB
makeIt :: IO ()
makeIt = makeCDB (do
addBS (B.pack "foo") (B.pack "bar")
addBS (B.pack "foo") (B.pack "baz")) "foo.cdb"
You can later use it as in:
getIt :: IO [ByteString]
getIt = do
f <- openCDB "foo.cdb"
bs <- getBS f (B.pack "foo")
closeCDB "foo.cdb"
return bs
getIt returns [ "bar", "baz" ] in unspecified order.
Note that pure-cdb works on strict ByteString's only for now.