hash-addressed: Hash-addressed file storage

[ apache, filesystem, hash, library ] [ Propose Tags ]

A simple system for maintaining a directory wherein each file's name is a hash of its content.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0.0, 0.0.1.0, 0.1.0.0, 0.2.0.0, 0.2.0.1
Change log changelog.md
Dependencies base (>=4.16 && <4.18), base16-bytestring (>=1.0.2 && <1.1), bytestring (>=0.11.3 && <0.12), cryptohash-sha256 (>=0.11.102 && <0.12), directory (>=1.3.6 && <1.4), filepath (>=1.4.2 && <1.5), gambler (>=0.0.0 && <0.1), mtl (>=2.2.2 && <2.3), pipes (>=4.3.16 && <4.4), quaalude (>=0.0.0 && <0.1), resourcet (>=1.2.6 && <1.3 || >=1.3.0 && <1.4), temporary (>=1.3 && <1.4) [details]
License Apache-2.0
Copyright 2023 Mission Valley Software LLC
Author Chris Martin
Maintainer Chris Martin, Julie Moronuki
Category Hash, Filesystem
Home page https://github.com/typeclasses/hash-addressed
Bug tracker https://github.com/typeclasses/hash-addressed/issues
Source repo head: git clone git://github.com/typeclasses/hash-addressed.git
Uploaded by chris_martin at 2023-02-08T19:09:46Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 233 total (15 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-02-08 [all 1 reports]

Readme for hash-addressed-0.2.0.0

[back to package description]

hash-addressed is a simple system for maintaining a directory wherein each file's name is a hash of its content.

import qualified HashAddressed.Directory    as Dir
import qualified HashAddressed.HashFunction as Hash
import qualified Data.ByteString.Lazy       as Lazy
import qualified Data.ByteString            as Strict

First define a ContentAddressedDirectory value by specifying which hash function to use and the path of the directory in which the files shall be kept. The directory does not need to already exist.

Dir.init :: Hash.HashFunction -> FilePath
    -> Dir.ContentAddressedDirectory

Presently the only supported hash function is Hash.SHA_256.

You can then write files into the directory using one of the two write functions:

Dir.writeLazy :: Dir.ContentAddressedDirectory
    -> Lazy.ByteString -> IO Dir.WriteResult
Dir.writeStreaming :: Dir.ContentAddressedDirectory
    -> (forall m. MonadIO m => (Strict.ByteString -> m ()) -> m ())
    -> IO Dir.WriteResult

The IO action returns a WriteResult, which gives you the path of the file in the store, including the path of the store itself. The WriteType value indicates whether the file was actually written by this action or was present in the store already.

data WriteResult = WriteResult{ contentAddressedFile :: FilePath,
                                writeType :: Dir.WriteType }
data WriteType = AlreadyPresent | NewContent

All operations that write into a hash-addressed directory are performed by first writing the content somewhere within the system temporary directory and then moving the file to its target location. This ensures that the store never makes visible the results of a partial write.