![Introducing Dashboard Analytics](https://cdn.sanity.io/images/cgdhsj6q/production/af327c5bd94708db501516a75da6870aef894c64-2286x1522.png?w=400&fit=max&auto=format)
Product
Introducing Dashboard Analytics
We're introducing a new Analytics feature in the Socket dashboard so you can view changes in your organization's and repositories' alerts over time.
ipfs-block-service
Advanced tools
IPFS implementation of the BlockService and Block data structure in JavaScript.
BlockService - A BlockService is a content-addressable store for blocks, providing an API for adding, deleting, and retrieving blocks. A BlockService is backed by an IPFS Repo as its datastore for blocks, and uses Bitswap to fetch blocks from the network.
┌────────────────────┐
│ BlockService │
└────────────────────┘
│
┌─────┴─────┐
▼ ▼
┌─────────┐ ┌───────┐
│IPFS Repo│ |Bitswap│
└─────────┘ └───────┘
> npm i ipfs-block-service
const BlockService = require('ipfs-block-service')
const BlockService = require('ipfs-block-service')
const Block = require('ipfs-block')
const IPFSRepo = require('ipfs-repo') // storage repo
const Store = require('interface-pull-blob-store') // in-memory store
// setup a repo
var repo = new IPFSRepo('example', { stores: Store })
// create a block
const block = new Block('hello world')
console.log(block.data)
console.log(block.key())
// create a service
const bs = new BlockService(repo)
// add the block, then retrieve it
bs.put({
block: block,
cid: cid,
}, function (err) {
bs.get(cid, function (err, b) {
console.log(block.data.toString() === b.data.toString())
})
})
outputs
<Buffer 68 65 6c 6c 6f 20 77 61 72 6c 64>
<Buffer 12 20 db 3c 15 23 3f f3 84 8f 42 fe 3b 74 78 90 90 5a 80 7e a6 ef 2b 6d 2f 3c 8b 2c b7 ae be 86 3c 4d>
true
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
var BlockService = require('ipfs-block-service')
<script>
TagLoading this module through a script tag will make the IpfsBlockService
obj available in
the global namespace.
<script src="https://unpkg.com/ipfs-block-service/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipfs-block-service/dist/index.js"></script>
const BlockService = require('ipfs-block-service')
new BlockService(repo)
repo: Repo
Creates a new block service backed by IPFS Repo repo
for storage.
goOnline(bitswap)
bitswap: Bitswap
Add a bitswap instance that communicates with the network to retreive blocks that are not in the local store.
If the node is online all requests for blocks first check locally and afterwards ask the network for the blocks.
goOffline()
Remove the bitswap instance and fall back to offline mode.
isOnline()
Returns a Boolean
indicating if the block service is online or not.
put(blockAndCID, callback)
blockAndCID: { block: block, cid: cid }
callback: Function
Asynchronously adds a block instance to the underlying repo.
putStream()
Returns a through pull-stream, which blockAndCID
s can be written to, and
that emits the meta data about the written block.
get(cid [, extension], callback)
cid: CID
extension: String
, defaults to 'data'callback: Function
Asynchronously returns the block whose content multihash matches multihash
.
getStream(cid [, extension])
cid: CID
extension: String
, defaults to 'data'Returns a source pull-stream, which emits the requested block.
delete(cids, [, extension], callback)
cids: CID | []CID
extension: String
, defaults to 'data' - extension: String
, defaults to 'data'callback: Function
Deletes all blocks referenced by multihashes.
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
0.8.1 (2017-01-29)
<a name="0.8.0"></a>
FAQs
JavaScript Implementation of BlockService
The npm package ipfs-block-service receives a total of 669 weekly downloads. As such, ipfs-block-service popularity was classified as not popular.
We found that ipfs-block-service demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Product
We're introducing a new Analytics feature in the Socket dashboard so you can view changes in your organization's and repositories' alerts over time.
Security News
A new OpenSSF report uncovers critical gaps in secure software training, with 75% of new developers unfamiliar with secure practices, highlighting urgent educational needs.
Security News
The 2023 Python Developers Survey reveals key trends in packaging, web frameworks, and developer demographics, highlighting a shift toward innovative tools as the Python community diversifies and grows among less experienced developers.