@ipld/dag-cbor
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "@ipld/dag-cbor", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "JS implementation of dag-cbor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -5,13 +5,11 @@ # @ipld/dag-cbor | ||
This is the *new* interface meant for use with `multiformats` and | ||
This is the *new* interface meant for use by itself or with `multiformats` and | ||
`@ipld/block`. It is not used by `js-ipld-format` which is currently | ||
used in IPFS. That library is [here](https://github.com/ipld/js-ipld-dag-cbor). | ||
Usage (w/ Block Interface): | ||
Usage: | ||
```javascript | ||
const multiformats = require('multiformats/basics') | ||
multiformats.add(require('@ipld/dag-cbor')) | ||
const Block = require('@ipld/block')(multiformats) | ||
const { CID } = multiformats | ||
import { encode, decode } from '@ipld/dag-cbor' | ||
import { CID } from 'multiformats' | ||
@@ -21,5 +19,5 @@ const obj = { | ||
/* CID instances are encoded as links */ | ||
y: [2, 3, CID.from('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')], | ||
y: [2, 3, CID.parse('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')], | ||
z: { | ||
a: CID.from('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4'), | ||
a: CID.parse('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4'), | ||
b: null, | ||
@@ -30,5 +28,4 @@ c: 'string' | ||
let encoder = Block.encoder(obj, 'dag-json') | ||
let encoded = await Block.encode() // binary encoded block | ||
let decoded = await Block.decoder(encoded, 'dag-json').decode() | ||
let data = encode(obj) | ||
let decoded = decode(data) | ||
decoded.y[0] // 2 | ||
@@ -35,0 +32,0 @@ CID.asCID(decoded.z.a) // cid instance |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8649
35