Stability | Experimental |
---|---|
Portability | non-portable (requires POSIX) |
Safe Haskell | None |
Language | Haskell2010 |
This module provides interface for handling large objects - also known as blobs.
One of the use cases for bloc is storing large objects in databases.
Instead of storing the entire blob in the database, you can just store
the BlobId
of the blob.
Multiple values in the database can share a BlobId
and we provide an
interface for garbage collection for such cases.
- newtype Blob = Blob ByteString
- data BlobId
- data BlobStore
- data WriteContext
- data ReadContext
- openBlobStore :: FilePath -> IO BlobStore
- newBlob :: BlobStore -> IO WriteContext
- writePartial :: WriteContext -> Blob -> IO WriteContext
- endWrite :: WriteContext -> IO BlobId
- createBlob :: BlobStore -> Blob -> IO BlobId
- startRead :: BlobId -> IO ReadContext
- readPartial :: ReadContext -> Int -> IO Blob
- skipBytes :: ReadContext -> Integer -> IO ()
- endRead :: ReadContext -> IO ()
- readBlob :: BlobId -> IO Blob
- deleteBlob :: BlobId -> IO ()
Documentation
This is used to store the base directory.
Each application should maintain there own BlobStores.
data WriteContext Source
WriteContext maintains the blob's state during writing.
data ReadContext Source
ReadContext maintains the reading state of a blob.
openBlobStore :: FilePath -> IO BlobStore Source
All the blobs of an application are stored in the
same directory. openBlobStore
returns the BlobStore
corresponding to a given directory.
newBlob :: BlobStore -> IO WriteContext Source
Creates an empty blob in the given BlobStore.
Use writePartial
to write contents to the newly
created blob.
writePartial :: WriteContext -> Blob -> IO WriteContext Source
writePartial
appends the given blob to the
blob referenced by the WriteContext
.
endWrite :: WriteContext -> IO BlobId Source
Finalize the write to the given blob.
After calling endWrite
no more updates are possible
on the blob.
createBlob :: BlobStore -> Blob -> IO BlobId Source
Create a blob from the given contents.
Use createBlob
only for small contents.
For large contents, use the partial write interface
(newBlob
followed by calls to writePartial
).
startRead :: BlobId -> IO ReadContext Source
Open blob for reading.
readPartial :: ReadContext -> Int -> IO Blob Source
Read given number of bytes from the blob.
skipBytes :: ReadContext -> Integer -> IO () Source
Skip given number of bytes ahead in the blob.
endRead :: ReadContext -> IO () Source
Complete reading from a blob.
readBlob :: BlobId -> IO Blob Source
readBlob
reads an entire blob.
Use readBlob
only for small blobs.
For large blobs, use readPartial
instead.
deleteBlob :: BlobId -> IO () Source
Deletes the given blob.
Use deleteBlob
only when you are sure that the given blob
is not accessible by anyone. If the blob is shared, you should
use the GC interface instead.