Skip to content

Commit

Permalink
Update Decoder.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Jan 13, 2025
1 parent 9b4bff9 commit 3bd8f57
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Core/CBOR/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
*/
final class Decoder
{
protected const MAX_SIZE = 1024 * 1024 * 5;

protected StreamInterface $stream;

protected int $stream_size = 0;

/**
* If the CBOR contains multiple data items, decode only the first item and return an array with the remainder left as is.
*/
Expand All @@ -31,7 +27,6 @@ public function decodeFirst(StreamInterface $stream): array
throw_unless($stream->isReadable());

$this->stream = $stream;
$this->stream_size = (int) min($stream->getSize(), self::MAX_SIZE);

$first = $this->readValue();
$remainder = $this->stream->getContents();
Expand Down Expand Up @@ -59,7 +54,6 @@ public function decodeAll(StreamInterface $stream): array
$arr = [];

$this->stream = $stream;
$this->stream_size = (int) min($stream->getSize(), self::MAX_SIZE);

while (! $stream->eof()) {
$value = $this->readValue();
Expand Down Expand Up @@ -141,17 +135,17 @@ private function readUint64(): int

private function readString(int $length): string
{
return $this->stream->read(min($length, $this->stream_size));
return $this->stream->read($length);
}

private function readBytes(int $length): AtBytes
{
return new AtBytes($this->stream->read(min($length, $this->stream_size)));
return new AtBytes($this->stream->read($length));
}

private function readCid(int $length): CIDLinkWrapper
{
$cid = $this->stream->read(min($length, $this->stream_size));
$cid = $this->stream->read($length);
$cid = Str::ltrim($cid, CID::ZERO);

return new CIDLinkWrapper($cid);
Expand Down

0 comments on commit 3bd8f57

Please sign in to comment.