Storage.Hashed

hashed-storage-0.5.9: Hashed file storage support code.

Storage.Hashed

Contents

- Obtaining Trees.
- Blob access.
- Writing trees.
- Unsafe functions for the curious explorer.

Synopsis

- readPlainTree :: FilePath -> IO (Tree IO)
- readDarcsHashed :: FilePath -> (Maybe Int, Hash) -> IO (Tree IO)
- readBlob :: Blob m -> m ByteString
- writePlainTree :: Tree IO -> FilePath -> IO ()
- writeDarcsHashed :: Tree IO -> FilePath -> IO Hash
- floatPath :: FilePath -> AnchoredPath
- printPath :: Tree IO -> FilePath -> IO ()

# Obtaining Trees.

Please note that Trees obtained this way will contain Stub items. These need to be executed (they are IO actions) in order to be accessed. Use `expand` to do this. However, many operations are perfectly fine to be used on a stubbed Tree (and it is often more efficient to do everything that can be done before expanding a Tree).

readPlainTree :: FilePath -> IO (Tree IO)

readDarcsHashed :: FilePath -> (Maybe Int, Hash) -> IO (Tree IO)

# Blob access.

readBlob :: Blob m -> m ByteString

Read a Blob into a Lazy ByteString. Might be backed by an mmap, use with care.

# Writing trees.

writePlainTree :: Tree IO -> FilePath -> IO ()

Write out full tree to a plain directory structure. If you instead want to make incremental updates, refer to Storage.Hashed.Monad.

writeDarcsHashed :: Tree IO -> FilePath -> IO Hash

Write a Tree into a darcs-style hashed directory.

# Unsafe functions for the curious explorer.

These are more useful for playing within ghci than for real, serious programs. They generally trade safety for conciseness. Please use responsibly. Don't kill innocent kittens.

floatPath :: FilePath -> AnchoredPath

Take a relative FilePath and turn it into an AnchoredPath. The operation is (relatively) unsafe. Basically, by using floatPath, you are testifying that the argument is a path relative to some common root -- i.e. the root of the associated Tree object. Also, there are certain invariants about AnchoredPath that this function tries hard to preserve, but probably cannot guarantee (i.e. this is a best-effort thing). You should sanitize any FilePaths before you declare them good by converting into AnchoredPath (using this function).

printPath :: Tree IO -> FilePath -> IO ()

Take a relative FilePath within a Tree and print the contents of the object there. Useful for exploration, less so for serious programming.