unpin method

Future<bool> unpin(
  1. String cid
)

Unpins a CID from IPFS.

This allows the content to be garbage collected if no other pins exist. Returns true if the unpin was successful, false otherwise.

Implementation

Future<bool> unpin(String cid) async {
  try {
    // Create a Pin instance
    final pin = Pin(
      cid: CID.decode(cid),
      type: PinTypeProto.PIN_TYPE_RECURSIVE,
      blockStore: _container.get<BlockStore>(),
    );

    // Attempt to unpin
    final success = await pin.unpin();

    if (success) {
      // Remove from pins in datastore using /pins/ key prefix
      final pinKey = Key('/pins/$cid');
      await _container.get<DatastoreHandler>().datastore.delete(pinKey);
    }

    return success;
  } catch (e) {
    return false;
  }
}