fliq/ipfs-laravel
最新稳定版本:v0.1.0
Composer 安装命令:
composer require fliq/ipfs-laravel
包简介
:package_description
关键字:
README 文档
README
Interact with IPFS in Laravel.
Installation
Via Composer
composer require fliq/ipfs-laravel
Usage
Basic usage
$cid = Ipfs::add('Hello, IPFS')->first()['Hash']; Ipfs::get($cid); // Hello, IPFS
Configuration
To publish your config run:
php artisan vendor:publish --tag=ipfs.config
Adding Files
You can flexibly add new files to IPFS using the add() method.
You can add files from a string, a resource or an array, arrays will be json encoded.
Use array keys to specify files names.
The second argument is an array of options more information on
the IPFS documentation.
The wrap-with-directoryoption will create an extra CID for the directory.
$resource = fopen('path/to/file.mp3'); $results = Ipfs::add([ 'hello.txt' => 'Hello, IPFS!', 'file.mp3' => $resource, 'meta.json' => [ 'name' => 'Hello', 'properties' => [...], ], ], ['wrap-with-directory' => true]); $cid = $results->last()['Hash']; Ipfs::get("{$cid}/hello.txt"); // Hello, IPFS!
Retrieving files
You can retrieve files using the cat(), get(), and json() methods.
cat()- Returns a StreamInterface
get()- returns a string
json()- returns a json decoded array
$stream = Ipfs::cat($cid); $str = Ipfs::get($cid); $array = Ipfs::json($cid);
Asynchronous requests
Use the async() method to make asynchronous requests.
Async requests return Promises
Ipfs::async()->add($file)->then(function(array $results) { $results[0]; // do something }); // or do multiple requests. $ipfs = Ipfs::async(); $promises = [ $ipfs->get($cid1), $ipfs->get($cid2), ]; $results = GuzzleHttp\Promise\Utils::unwrap($promises);
Testing
$ composer test
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email author@email.com instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-04