refactor tests

This commit is contained in:
Jaremy Creechley 2023-09-27 18:27:29 -07:00
parent c215f9cb1a
commit ef5a30f7d3
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 6 additions and 5 deletions

View File

@ -111,12 +111,13 @@ proc readFile[V](self: FSDatastore, path: string): ?!V =
when V is seq[byte]:
var bytes = newSeq[byte](size)
elif V is DataBuffer:
var bytes = DataBuffer.new(capacity=size)
var bytes = DataBuffer.new(size=size)
else:
{.error: "unhandled result type".}
var
read = 0
echo "BYTES: ", bytes.repr
while read < size:
read += file.readBytes(bytes.toOpenArray(), read, size)

View File

@ -47,14 +47,14 @@ template `==`*[T: char | byte](a: DataBuffer, b: openArray[T]): bool =
elif a[].size != b.len: false
else: a.hash() == b.hash()
proc new*(tp: type DataBuffer, capacity: int = 0): DataBuffer =
proc new*(tp: type DataBuffer, size: int = 0): DataBuffer =
## allocate new buffer with given capacity
##
newSharedPtr(DataBufferHolder(
buf: cast[typeof(result[].buf)](allocShared0(capacity)),
size: 0,
cap: capacity,
buf: cast[typeof(result[].buf)](allocShared0(size)),
size: size,
cap: size,
))
proc new*[T: byte | char](tp: type DataBuffer, data: openArray[T], opts: set[DataBufferOpt] = {}): DataBuffer =