Bitpeace

trait Bitpeace[F[_]]

A store for binary data.

Binary data is given as a stream of bytes. The stream is saved in chunks, where each chunk is stored into a blob object (in contrast to use one blob for the whole data). This makes it possible to effectively retrieve partial content.

Companion
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def addChunk(chunk: FileChunk, chunksize: Int, totalChunks: Int, hint: MimetypeHint): Stream[F, Outcome[FileMeta]]

Adds a new chunk of data to a file.

Adds a new chunk of data to a file.

Creates or updates the corresponding FileMeta record and returns it. This is useful if you get chunks of data in some random order.

If the chunk already exists with correct length, the return value is wrapped in Outcome.Unmodified and the given chunk is not written, otherwise a Outcome#Created is returned and the chunk is stored.

def chunkExists(id: String, chunkNr: Long): Stream[F, Boolean]

Return whether a file with given id has a chunk with the given chunkNr.

Return whether a file with given id has a chunk with the given chunkNr.

def chunkExistsRemove(id: String, chunkNr: Long, chunkLength: Long): Stream[F, Boolean]

Like

Like

chunkExists}} but also checks the chunk size. If a chunk
with different size exists, it is removed and {{{false

is returned.

with different size exists, it is removed and {{{false }}} returned.

def count: Stream[F, Long]

Count all FileMeta rows.

Count all FileMeta rows.

def delete(id: String): Stream[F, Boolean]

Deletes the file data and meta-data.

Deletes the file data and meta-data.

def exists(id: String): Stream[F, Boolean]

Return whether a file with a given id exists.

Return whether a file with a given id exists.

def fetchData(range: RangeDef): (F, FileMeta) => Byte

Fetch data using one connection per chunk. So connections are closed immediately after reading a chunk.

Fetch data using one connection per chunk. So connections are closed immediately after reading a chunk.

def fetchData2(range: RangeDef): (F, FileMeta) => Byte

Fetch data using one connection for the whole stream. It is closed once the stream terminates.

Fetch data using one connection for the whole stream. It is closed once the stream terminates.

def get(id: String): Stream[F, Option[FileMeta]]

Return meta data about one file.

Return meta data about one file.

def getChunks(id: String, offset: Option[Int], limit: Option[Int]): Stream[F, FileChunk]

Get chunks using one connection.

Get chunks using one connection.

def makeUnique(meta: FileMeta): Stream[F, Outcome[FileMeta]]

“Merge” duplicates.

“Merge” duplicates.

If the given

meta

object contains a random id (as returned from

saveNew

), check for duplicates using its checksum.

If a duplicate is found, delete

meta

and its data and return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}} return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

saveNew }}}

If a duplicate is found, delete

meta

and its data and return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}} return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}} from

saveNew

), check for duplicates using its checksum.

If a duplicate is found, delete

meta

and its data and return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}} return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

saveNew }}}

If a duplicate is found, delete

meta

and its data and return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}} return the just found value. If no duplicate is found, update the id of

meta

to be its checksum.

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

meta }}}

Return

Outcome.Unmodified

if there was a duplicate, or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

Outcome.Unmodified }}} or

Outcome.Created

if there was no duplicate.

Outcome.Created }}}

def saveFileChunk(fc: FileChunk): Stream[F, Unit]

Insert the chunk object.

Insert the chunk object.

def saveFileMeta(fm: FileMeta): Stream[F, Unit]

Insert the file meta object.

Insert the file meta object.

def saveNew(data: Stream[F, Byte], chunkSize: Int, hint: MimetypeHint, fileId: Option[String], time: Instant): Stream[F, FileMeta]

Save data in chunks of size chunkSize and use a random id.

Save data in chunks of size chunkSize and use a random id.

Concrete methods

def addChunkByLength(chunk: FileChunk, chunksize: Int, length: Long, hint: MimetypeHint): Stream[F, Outcome[FileMeta]]

Calculates the total number of chunks from the given length and calls addChunk.

Calculates the total number of chunks from the given length and calls addChunk.

def save(data: Stream[F, Byte], chunkSize: Int, hint: MimetypeHint, time: Instant): Stream[F, Outcome[FileMeta]]

Save data in chunks of size chunkSize and check for duplicates.

Save data in chunks of size chunkSize and check for duplicates.

Return either

Outcome.Created

if new data has been written (no duplicates) or

Outcome.Unmodified

if no data was written and the duplicate is returned.

Outcome.Unmodified }}} written and the duplicate is returned.

Outcome.Created }}} (no duplicates) or

Outcome.Unmodified

if no data was written and the duplicate is returned.

Outcome.Unmodified }}} written and the duplicate is returned.