From 216ca4099b56a12e66d5750bdf80d4477155ff0c Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 21 Feb 2024 17:42:25 +0000 Subject: [PATCH] chore: remove error test --- packages/car/package.json | 4 +--- packages/car/src/index.ts | 32 +++++--------------------------- packages/car/test/stream.spec.ts | 20 +------------------- 3 files changed, 7 insertions(+), 49 deletions(-) diff --git a/packages/car/package.json b/packages/car/package.json index 4cab672f6..dfa5ce438 100644 --- a/packages/car/package.json +++ b/packages/car/package.json @@ -145,7 +145,6 @@ "interface-blockstore": "^5.2.9", "it-drain": "^3.0.5", "it-map": "^3.0.5", - "it-merge": "^3.0.3", "multiformats": "^13.0.1", "p-defer": "^4.0.0", "p-queue": "^8.0.1", @@ -157,7 +156,6 @@ "aegir": "^42.2.2", "blockstore-core": "^4.4.0", "ipfs-unixfs-importer": "^15.2.4", - "it-to-buffer": "^4.0.5", - "sinon": "^17.0.1" + "it-to-buffer": "^4.0.5" } } diff --git a/packages/car/src/index.ts b/packages/car/src/index.ts index f10b033cf..b97acff88 100644 --- a/packages/car/src/index.ts +++ b/packages/car/src/index.ts @@ -61,7 +61,6 @@ import { CarWriter } from '@ipld/car' import drain from 'it-drain' import map from 'it-map' -import merge from 'it-merge' import defer from 'p-defer' import PQueue from 'p-queue' import type { DAGWalker } from '@helia/interface' @@ -193,49 +192,28 @@ class DefaultCar implements Car { await writer.put({ cid, bytes }) }, options) }) + .catch(() => {}) } - let exportError: Error | undefined - // wait for the writer to end try { await deferred.promise } finally { await writer.close() } - - if (exportError != null) { - throw exportError - } } async * stream (root: CID | CID[], options?: AbortOptions & ProgressOptions): AsyncGenerator { const { writer, out } = CarWriter.create(root) - const deferred = defer() // has to be done async so we write to `writer` and read from `out` at the // same time this.export(root, writer, options) - .then(() => { - deferred.resolve() - }) - .catch((err) => { - deferred.reject(err) - }) + .catch(() => {}) - yield * merge( - (async function * () { - // out is AsyncIterable not AsyncIterator so we - // can't just `yield * out` - for await (const buf of out) { - yield buf - } - })(), - // eslint-disable-next-line require-yield - (async function * () { - await deferred.promise - })() - ) + for await (const buf of out) { + yield buf + } } /** diff --git a/packages/car/test/stream.spec.ts b/packages/car/test/stream.spec.ts index fedf26459..51563817e 100644 --- a/packages/car/test/stream.spec.ts +++ b/packages/car/test/stream.spec.ts @@ -4,10 +4,9 @@ import { type UnixFS, unixfs } from '@helia/unixfs' import { expect } from 'aegir/chai' import { MemoryBlockstore } from 'blockstore-core' import toBuffer from 'it-to-buffer' -import Sinon from 'sinon' import { car, type Car } from '../src/index.js' import { dagWalkers } from './fixtures/dag-walkers.js' -import { largeFile, smallFile } from './fixtures/files.js' +import { smallFile } from './fixtures/files.js' import { memoryCarWriter } from './fixtures/memory-car.js' import type { Blockstore } from 'interface-blockstore' @@ -35,21 +34,4 @@ describe('stream car file', () => { expect(bytes).to.equalBytes(streamed) }) - - it('errors when writing during streaming car file', async () => { - const exportSpy = Sinon.spy(c, 'export') - const cid = await u.addBytes(largeFile) - const iter = c.stream(cid) - - // start stream moving so we can get at the CAR writer - await iter.next() - - expect(exportSpy.called).to.be.true() - - // make the next write error - const writer = exportSpy.getCall(0).args[1] - writer.put = async () => { - throw new Error('Urk!') - } - }) })