mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-22 17:48:24 +00:00
29 lines
777 B
Nim
29 lines
777 B
Nim
|
## Nim-Dagger
|
||
|
## Copyright (c) 2021 Status Research & Development GmbH
|
||
|
## Licensed under either of
|
||
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||
|
## at your option.
|
||
|
## This file may not be copied, modified, or distributed except according to
|
||
|
## those terms.
|
||
|
|
||
|
{.push raises: [Defect].}
|
||
|
|
||
|
import pkg/questionable
|
||
|
import pkg/questionable/results
|
||
|
|
||
|
import ./blockstream
|
||
|
import ./chunker
|
||
|
|
||
|
type
|
||
|
ChunkedBlockStreamRef* = ref object of BlockStreamRef
|
||
|
chunker*: Chunker
|
||
|
|
||
|
method nextBlock*(c: ChunkedBlockStreamRef): ?!Block =
|
||
|
let data: seq[byte] = c.chunker.getBytes()
|
||
|
if data.len > 0:
|
||
|
return success Block.new(data)
|
||
|
|
||
|
proc new*(T: type ChunkedBlockStreamRef, chunker: Chunker): T =
|
||
|
T(chunker: chunker)
|