New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ipld/block

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ipld/block

IPLD Block interface

  • 2.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34
increased by36%
Maintainers
3
Weekly downloads
 
Created
Source

Block API

238714 72121

The Block API is the single endpoint for authoring IPLD data structures. Unless you're implementing a new codec you can get everything you need from the Block API: encoding, decoding, cid creation w/ hashing.

Block.encoder(object, codec, algorithm = 'sha2-256')

Create a Block instance from a native object.

The cid as well as encoding will not happen until requested and then will be cached when appropriate.

let block = Block.encoder({hello: 'world'}, 'dag-cbor')

Returns a Block instance.

Block.decoder(binary, codec, algorithm = 'sha2-256')

Create a Block instance from an existing binary encoded block

The cid as well as decoding will not happen until requested and then will be cached when appropriate.

let block = Block.decoder(someBuffer, 'dag-cbor')

Returns a Block instance.

Block.create(binary, cid)

Create a new block from the raw binary data and cid.

cid can be an instance of CID or a base encoded string of a cid.

Returns a Block instance.

Block(opts)

Once a block instance is created the information represented in the block is considered immutable.

block.decode()

Promise that resolves to a native JavaScript object decoded from the block data.

A new object is returned on every call. The decoding is not cached because it is likely to be mutated by the consumer.

block.cid()

Promise that resolves to a cid instance. Cached after creation.

block.encode()

Promise that resolves to a Buffer instance encoded from the source input.

block.reader()

Returns an instance of Reader() from the codec implementation.

block.validate()

Returns true/false if the CID's multihash matches the given block.

If a CID hasn't been created yet it will return true since we know the hash will match in our eventually created CID.

FAQs

Package last updated on 22 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc