@ipld/block
Advanced tools
Comparing version 2.1.4 to 2.2.0
@@ -119,2 +119,9 @@ 'use strict' | ||
} | ||
async equals (block) { | ||
if (block === this) return true | ||
const cid = await this.cid() | ||
if (CID.isCID(block)) return cid.equals(block) | ||
return cid.equals(await block.cid()) | ||
} | ||
} | ||
@@ -121,0 +128,0 @@ |
{ | ||
"name": "@ipld/block", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "directories": { |
# Block API | ||
  | ||
  | ||
@@ -5,0 +5,0 @@ The `Block` API is the single endpoint for authoring IPLD data structures. Unless you're |
@@ -142,1 +142,11 @@ 'use strict' | ||
}) | ||
test('block equals', async () => { | ||
const block1 = Block.encoder({ hello: 'world' }, 'dag-cbor') | ||
const block2 = Block.encoder({ hello: 'world' }, 'dag-cbor') | ||
const block3 = Block.encoder('hello world', 'dag-cbor') | ||
same(await block1.equals(block1), true) | ||
same(await block1.equals(await block1.cid()), true) | ||
same(await block1.equals(block2), true) | ||
same(await block1.equals(block3), false) | ||
}) |
15507
291