hash-store-0.1.0: Hash as cache

Safe HaskellNone
LanguageHaskell2010

HashStore

Synopsis

Documentation

hashStore Source #

Arguments

:: FilePath

Directory to store file contents with new hash

-> (ByteString -> IO ByteString)

Action to be performed if hash is different

-> (String, ByteString)

File name

-> IO String

File name with hash

hashStore storePath action (name, content) computes hash of content and performs action if file storePath/hash-name doesn't exist, writing new content in this file.

The property is that for any item (name, hash), we get a valid filepath by storePath/hash-name.

This functions solves the following problem. The caller doesn't need the content. Then it is better not to return the bytestring (we avoid the overhrad of reading the file in the cache hit case).

hashStoreWithContent Source #

Arguments

:: FilePath

Directory to store file contents with new hash

-> (ByteString -> IO ByteString)

Action to be performed if hash is different

-> (String, ByteString)

File name

-> IO (String, ByteString)

File name with hash and content of file

Like hashStore but also returns file content of hashed file.

This functions solves the following problem. The caller needs the file content. Then it's better to return the bytestring (we avoid the overhead of reading the file in the cache miss case).