11import filter from 'it-filter'
22import forEach from 'it-foreach'
33import { CustomProgressEvent , type ProgressOptions } from 'progress-events'
4- import type { Blocks , Pair , DeleteManyBlocksProgressEvents , DeleteBlockProgressEvents , GetBlockProgressEvents , GetManyBlocksProgressEvents , PutManyBlocksProgressEvents , PutBlockProgressEvents , GetAllBlocksProgressEvents } from '@helia/interface/blocks'
4+ import type { Blocks , Pair , DeleteManyBlocksProgressEvents , DeleteBlockProgressEvents , GetBlockProgressEvents , GetManyBlocksProgressEvents , PutManyBlocksProgressEvents , PutBlockProgressEvents , GetAllBlocksProgressEvents , GetOfflineOptions } from '@helia/interface/blocks'
55import type { AbortOptions } from '@libp2p/interfaces'
66import type { Blockstore } from 'interface-blockstore'
77import type { AwaitIterable } from 'interface-store'
@@ -82,8 +82,8 @@ export class NetworkedStorage implements Blocks {
8282 /**
8383 * Get a block by cid
8484 */
85- async get ( cid : CID , options : AbortOptions & ProgressOptions < GetBlockProgressEvents > = { } ) : Promise < Uint8Array > {
86- if ( this . bitswap ?. isStarted ( ) != null && ! ( await this . child . has ( cid ) ) ) {
85+ async get ( cid : CID , options : GetOfflineOptions & AbortOptions & ProgressOptions < GetBlockProgressEvents > = { } ) : Promise < Uint8Array > {
86+ if ( options . offline !== true && this . bitswap ?. isStarted ( ) != null && ! ( await this . child . has ( cid ) ) ) {
8787 options . onProgress ?.( new CustomProgressEvent < CID > ( 'blocks:get:bitswap:get' , cid ) )
8888 const block = await this . bitswap . want ( cid , options )
8989
@@ -101,11 +101,11 @@ export class NetworkedStorage implements Blocks {
101101 /**
102102 * Get multiple blocks back from an (async) iterable of cids
103103 */
104- async * getMany ( cids : AwaitIterable < CID > , options : AbortOptions & ProgressOptions < GetManyBlocksProgressEvents > = { } ) : AsyncIterable < Pair > {
104+ async * getMany ( cids : AwaitIterable < CID > , options : GetOfflineOptions & AbortOptions & ProgressOptions < GetManyBlocksProgressEvents > = { } ) : AsyncIterable < Pair > {
105105 options . onProgress ?.( new CustomProgressEvent ( 'blocks:get-many:blockstore:get-many' ) )
106106
107107 yield * this . child . getMany ( forEach ( cids , async ( cid ) : Promise < void > => {
108- if ( this . bitswap ?. isStarted ( ) === true && ! ( await this . child . has ( cid ) ) ) {
108+ if ( options . offline !== true && this . bitswap ?. isStarted ( ) === true && ! ( await this . child . has ( cid ) ) ) {
109109 options . onProgress ?.( new CustomProgressEvent < CID > ( 'blocks:get-many:bitswap:get' , cid ) )
110110 const block = await this . bitswap . want ( cid , options )
111111 options . onProgress ?.( new CustomProgressEvent < CID > ( 'blocks:get-many:blockstore:put' , cid ) )
0 commit comments