Copyright | (c) Miles J. Litteral 2023 |
---|---|
License | BSD-3 |
Maintainer | mandaloe2@gmail.com |
Stability | release |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
- newtype MegaStore = MegaStore {
- _contents :: [(Text, ByteString)]
- saveStore :: String -> MegaStore -> IO ()
- loadStore :: FilePath -> IO MegaStore
- loadFile :: FilePath -> IO ByteString
- loadDirectory :: FilePath -> IO [ByteString]
- createMegaStoreWithBulk :: [ByteString] -> Text -> MegaStore
- unpackStore :: ByteString -> IO (Image PixelRGBA8)
- unpackStore' :: String -> Image PixelRGBA8 -> IO ()
- autoUnpack :: String -> MegaStore -> IO ()
- append :: (Text, ByteString) -> MegaStore -> MegaStore
- search :: String -> [(Text, ByteString)] -> Maybe ByteString
- keyExists :: String -> [(Text, ByteString)] -> Bool
- remove :: String -> MegaStore -> MegaStore
- remove' :: Int -> MegaStore -> MegaStore
- megastoreToMap :: MegaStore -> Map Text ByteString
- mapToMegaStore :: Map Text ByteString -> MegaStore
Records
The MegaStore Data Type itself, fundamentally it is a List of Tuples
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
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
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