From 2f9d495bf9045891acd9c004cd32651705694d75 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:09:13 -0600 Subject: [PATCH] fix: attempt to use peek.. doesnt seem to help --- .../src/utils/enhanced-dag-traversal.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/verified-fetch/src/utils/enhanced-dag-traversal.ts b/packages/verified-fetch/src/utils/enhanced-dag-traversal.ts index e2ba7a6..29fea98 100644 --- a/packages/verified-fetch/src/utils/enhanced-dag-traversal.ts +++ b/packages/verified-fetch/src/utils/enhanced-dag-traversal.ts @@ -1,7 +1,7 @@ import { type ComponentLogger } from '@libp2p/interface' import { type ReadableStorage, exporter, type ExporterOptions } from 'ipfs-unixfs-exporter' import first from 'it-first' -// import peekable from 'it-peekable' +import peekable from 'it-peekable' import toBrowserReadableStream from 'it-to-browser-readablestream' import { type CID } from 'multiformats/cid' import { type ContentTypeParser } from '../types.js' @@ -50,7 +50,14 @@ export async function enhancedDagTraversal ({ let error: Error try { // Fetch the first chunk eagerly - firstChunk = await first(dfsIter) + const peekableIter = peekable(dfsIter) + const firstPeek = await peekableIter.peek() + if (firstPeek.done === true) { + throw new Error('No content found') + } + // firstChunk = await first(dfsIter) + firstChunk = firstPeek.value + peekableIter.push(firstChunk) } catch (err: any) { if (signal?.aborted === true) { error = err