|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 | 3 | const promisify = require('promisify-es6')
|
4 |
| -const dagPB = require('ipld-dag-pb') |
5 |
| -const DAGNode = dagPB.DAGNode |
6 |
| -const LRU = require('lru-cache') |
7 |
| -const lruOptions = { |
8 |
| - max: 128 |
9 |
| -} |
| 4 | +const CID = require('cids') |
| 5 | +const { DAGNode } = require('ipld-dag-pb') |
10 | 6 |
|
11 |
| -const cache = LRU(lruOptions) |
12 | 7 | const SendOneFile = require('../utils/send-one-file')
|
13 | 8 | const once = require('once')
|
14 | 9 |
|
@@ -72,49 +67,7 @@ module.exports = (send) => {
|
72 | 67 | return callback(err) // early
|
73 | 68 | }
|
74 | 69 |
|
75 |
| - if (Buffer.isBuffer(obj)) { |
76 |
| - if (!options.enc) { |
77 |
| - obj = { Data: obj, Links: [] } |
78 |
| - } else if (options.enc === 'json') { |
79 |
| - obj = JSON.parse(obj.toString()) |
80 |
| - } |
81 |
| - } |
82 |
| - |
83 |
| - let node |
84 |
| - |
85 |
| - if (DAGNode.isDAGNode(obj)) { |
86 |
| - node = obj |
87 |
| - } else if (options.enc === 'protobuf') { |
88 |
| - dagPB.util.deserialize(obj, (err, _node) => { |
89 |
| - if (err) { |
90 |
| - return callback(err) |
91 |
| - } |
92 |
| - node = _node |
93 |
| - next() |
94 |
| - }) |
95 |
| - return |
96 |
| - } else { |
97 |
| - DAGNode.create(Buffer.from(obj.Data), obj.Links, (err, _node) => { |
98 |
| - if (err) { |
99 |
| - return callback(err) |
100 |
| - } |
101 |
| - node = _node |
102 |
| - next() |
103 |
| - }) |
104 |
| - return |
105 |
| - } |
106 |
| - next() |
107 |
| - |
108 |
| - function next () { |
109 |
| - dagPB.util.cid(node, (err, cid) => { |
110 |
| - if (err) { |
111 |
| - return callback(err) |
112 |
| - } |
113 |
| - |
114 |
| - cache.set(cid.toBaseEncodedString(), node) |
115 |
| - callback(null, node) |
116 |
| - }) |
117 |
| - } |
| 70 | + callback(null, new CID(result.Hash)) |
118 | 71 | })
|
119 | 72 | })
|
120 | 73 | }
|
0 commit comments