• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ipfs-inactive/js-ipfs-unixfs-engine: [ARCHIVED] JavaScript implementation of the ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ipfs-inactive/js-ipfs-unixfs-engine

开源软件地址:

https://github.com/ipfs-inactive/js-ipfs-unixfs-engine

开源编程语言:

JavaScript 100.0%

开源软件介绍:

[ARCHIVED]

This module has been merged into ipfs/js-ipfs-unixfs where development continues. Please open issues/PRs there.

ipfs-unixfs-engine

standard-readme compliant Build Status Codecov Dependency Status js-standard-style

JavaScript implementation of the layout and chunking mechanisms used by IPFS to handle Files

Lead Maintainer

Alex Potsides

Table of Contents

Install

> npm install ipfs-unixfs-engine

Usage

The unixfs-engine exports the unixfs-importer and unixfs-exporter modules. Please see those modules for for full documentation.

Importing a file

The importer is a pull-stream through which takes objects of the form { path, content } where path is a string path and content can be a Buffer, a ReadableStream or a pull-stream that emits Buffers.

It requires an ipld resolver to persist DAGNodes and make them available over IPFS.

See the unixfs-importer module for full documentation.

const {
  importer
} = require('ipfs-unixfs-engine')
const pull = require('pull-stream')
const fs = require('fs')

// Import path /tmp/bar.txt
pull(
  pull.values([{
    path: '/tmp/bar.txt',
    content: fs.createReadStream('/tmp/bar.txt')
  }]),

  // You need to create and pass an ipld resolver instance
  // https://npmjs.com/packages/ipld
  importer(<ipld-resolver instance>, <options>),

  // Handle the error and do something with the results
  pull.collect((err, files) => {
    console.info(files)

    // Prints:
    // [{
    //   size: 12,
    //   leafSize: 4,
    //   multihash: <Buffer>
    //   path: '/tmp/bar.txt',
    //   name: ''
    // }, {
    //   path: 'tmp',
    //   multihash: <Buffer>
    //   size: 65
    // }]
  })
)

Exporting a file

The exporter is a pull-stream source which takes a cid and an ipld resolver.

See the unixfs-exporter module for full documentation.

const {
  exporter
} = require('ipfs-unixfs-engine').exporter
const pull = require('pull-stream')
const drain = require('pull-stream/sinks/drain')

pull(
  // You need to create and pass an ipld resolver instance
  // https://npmjs.com/packages/ipld
  exporter(cid, ipld),
  drain((file) => {
    // file.content is a pull stream containing the bytes of the file
  })
)

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap