logos-storage-nim/dagger/blockstream/chunkedblockstream.nim

29 lines
770 B
Nim
Raw Permalink Normal View History

2021-08-27 11:44:43 -06:00
## 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
2021-08-27 15:37:24 -06:00
import ../chunker
2021-08-27 11:44:43 -06:00
type
ChunkedBlockStreamRef* = ref object of BlockStreamRef
chunker*: Chunker
method nextBlock*(c: ChunkedBlockStreamRef): ?!Block =
let data: seq[byte] = c.chunker.getBytes()
if data.len > 0:
2021-08-27 15:37:24 -06:00
return Block.new(data)
2021-08-27 11:44:43 -06:00
2021-08-27 15:37:24 -06:00
func new*(T: type ChunkedBlockStreamRef, chunker: Chunker): T =
2021-08-27 11:44:43 -06:00
T(chunker: chunker)