megastore-0.1.0.0: Bulk image or strict bytestring storage
Copyright(c) Miles J. Litteral 2023
LicenseBSD-3
Maintainermandaloe2@gmail.com
Stabilityrelease
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

MegaStore

Description

A Module for taking a directory of images (for example) and turning them into a key referencable data structure that will efficiently store all images. Here is a quick crash course:

       a1  <- loadFile "s1.png"
       a2  <- loadFile "s2.png"
       a3  <- loadFile "s3.png"

       let testSet = KeyStore [("s1", a1), ("s2", a2), ("s3", a3)]
       saveStore ".testtestSet" testSet

       loadedContents <- loadStore ".testtestSet.keystore"
       autoUnpack "./results" loadedContents
   
Synopsis

Records

newtype MegaStore Source #

The MegaStore Data Type itself, fundamentally it is a List of Tuples

Constructors

MegaStore 

Fields

  • _contents :: [(Text, ByteString)]

    the contents of the MegaStore, while made for images it is acknowledged anything that satisfies the constraint/assertion may be a KeyStore

Instances

Instances details
Show MegaStore Source # 
Instance details

Defined in MegaStore

Binary MegaStore Source #

The MegaStore Data Type's instance for serializing the data structure to file type,

Instance details

Defined in MegaStore

Eq MegaStore Source # 
Instance details

Defined in MegaStore

Ord MegaStore Source # 
Instance details

Defined in MegaStore

I/O Functions

saveStore :: String -> MegaStore -> IO () Source #

Writes a MegaStore to physical memory, it does so via Data.ByteString.Lazy.WriteFile Where the data is compressed and encoded to Strict ByteStrings

loadStore :: FilePath -> IO MegaStore Source #

Read a MegaStore from file system path, it reads the file, decodes, and decompresses the data

loadFile :: FilePath -> IO ByteString Source #

Load an Image as a ByteString via Path

loadDirectory :: FilePath -> IO [ByteString] Source #

Load a directory of Images as ByteStrings via FilePath

createMegaStoreWithBulk :: [ByteString] -> Text -> MegaStore Source #

Pass a List of ByteStrings (this is intended to work with loadImageDirectory), and a String for a naming scheme (ie: S results in [S0..]) Example (Loading a Directory all at once): @ assets <- loadDirectory "./assets" saveStore ".testtestSet" $ createMegastoreWithBulk assets "s"

unpackStore :: ByteString -> IO (Image PixelRGBA8) Source #

Convert a ByteString back into it's original Image Data Type

unpackStore' :: String -> Image PixelRGBA8 -> IO () Source #

Convert a ByteString back into it's original Image File Type You have the added option of designating where the file will be savved

autoUnpack :: String -> MegaStore -> IO () Source #

Similar to unpackStore' except that it will turn an entire MegaStore record into it's Original Image File Type(s) and save the result at a designated file save path

Utility Functions

append :: (Text, ByteString) -> MegaStore -> MegaStore Source #

Key can be Str here which will be hashed, either way it will end up as a (String, BS.ByteString)

search :: String -> [(Text, ByteString)] -> Maybe ByteString Source #

This takes a key and returns a strict bytestring if the key is valid, Nothing is returned otherwise

keyExists :: String -> [(Text, ByteString)] -> Bool Source #

all the side effects of search come with this function

remove :: String -> MegaStore -> MegaStore Source #

Search the entire store for a key and delete it's associated entry

remove' :: Int -> MegaStore -> MegaStore Source #

Remove an entry by literal index in the MegaStore

megastoreToMap :: MegaStore -> Map Text ByteString Source #

Convenience Function for easy conversion to a Data.Map

mapToMegaStore :: Map Text ByteString -> MegaStore Source #

Convenience Function for easy conversion from a Data.Map