Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 357049d

Browse files
committed
fix: Ref -> ref
1 parent f252160 commit 357049d

6 files changed

+38
-16
lines changed

src/files-regular/refs-local-pull-stream.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ module.exports = (send) => {
1818
send({ path: 'refs/local', qs: opts }, (err, stream) => {
1919
if (err) { return p.resolve(pull.error(err)) }
2020

21-
p.resolve(toPull.source(stream))
21+
p.resolve(pull(
22+
toPull.source(stream),
23+
pull.map(r => ({ ref: r.Ref, err: r.Err }))
24+
))
2225
})
2326

2427
return p

src/files-regular/refs-local-readable-stream.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const cleanCID = require('../utils/clean-cid')
44
const v = require('is-ipfs')
55
const Stream = require('readable-stream')
66
const pump = require('pump')
7+
const through = require('through2')
78

89
module.exports = (send) => {
910
return (opts) => {
@@ -14,7 +15,9 @@ module.exports = (send) => {
1415
send({ path: 'refs/local', qs: opts }, (err, stream) => {
1516
if (err) { return pt.destroy(err) }
1617

17-
pump(stream, pt)
18+
pump(stream, through.obj(function (r, enc, cb) {
19+
cb(null, { ref: r.Ref, err: r.Err })
20+
}), pt)
1821
})
1922

2023
return pt

src/files-regular/refs-local.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const IsIpfs = require('is-ipfs')
44
const promisify = require('promisify-es6')
5-
const streamToValue = require('../utils/stream-to-value')
5+
const streamToValueWithTransformer = require('../utils/stream-to-value-with-transformer')
66
const moduleConfig = require('../utils/module-config')
77
const cleanCID = require('../utils/clean-cid')
88

@@ -15,11 +15,20 @@ module.exports = (arg) => {
1515
opts = {}
1616
}
1717

18+
const transform = (res, cb) => {
19+
cb(null, res.map(r => ({ ref: r.Ref, err: r.Err })))
20+
}
21+
1822
const request = {
1923
path: 'refs/local',
2024
qs: opts
2125
}
26+
send(request, (err, result) => {
27+
if (err) {
28+
return callback(err)
29+
}
2230

23-
send.andTransform(request, streamToValue, callback)
31+
streamToValueWithTransformer(result, transform, callback)
32+
})
2433
})
2534
}

src/files-regular/refs-pull-stream.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ module.exports = (send) => {
2626
send({ path: 'refs', args: hash, qs: opts }, (err, stream) => {
2727
if (err) { return p.resolve(pull.error(err)) }
2828

29-
p.resolve(toPull.source(stream))
29+
p.resolve(pull(
30+
toPull.source(stream),
31+
pull.map(r => ({ ref: r.Ref, err: r.Err }))
32+
))
3033
})
3134

3235
return p

src/files-regular/refs-readable-stream.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const cleanCID = require('../utils/clean-cid')
44
const v = require('is-ipfs')
55
const Stream = require('readable-stream')
66
const pump = require('pump')
7+
const through = require('through2')
78

89
module.exports = (send) => {
910
return (hash, opts) => {
@@ -22,7 +23,9 @@ module.exports = (send) => {
2223
send({ path: 'refs', args: hash, qs: opts }, (err, stream) => {
2324
if (err) { return pt.destroy(err) }
2425

25-
pump(stream, pt)
26+
pump(stream, through.obj(function (r, enc, cb) {
27+
cb(null, { ref: r.Ref, err: r.Err })
28+
}), pt)
2629
})
2730

2831
return pt

src/files-regular/refs.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
const IsIpfs = require('is-ipfs')
44
const promisify = require('promisify-es6')
5-
const streamToValue = require('../utils/stream-to-value')
5+
const streamToValueWithTransformer = require('../utils/stream-to-value-with-transformer')
66
const moduleConfig = require('../utils/module-config')
77
const cleanCID = require('../utils/clean-cid')
88

9-
function valueOrStreamToValue (response, callback) {
10-
if (typeof response.pipe === 'function') {
11-
streamToValue(response, callback)
12-
} else {
13-
callback(null, response)
14-
}
15-
}
16-
179
module.exports = (arg) => {
1810
const send = moduleConfig(arg)
1911

@@ -31,13 +23,22 @@ module.exports = (arg) => {
3123
}
3224
}
3325

26+
const transform = (res, cb) => {
27+
cb(null, res.map(r => ({ ref: r.Ref, err: r.Err })))
28+
}
29+
3430
const request = {
3531
path: 'refs',
3632
args: args,
3733
qs: opts
3834
}
35+
send(request, (err, result) => {
36+
if (err) {
37+
return callback(err)
38+
}
3939

40-
send.andTransform(request, valueOrStreamToValue, callback)
40+
streamToValueWithTransformer(result, transform, callback)
41+
})
4142
})
4243

4344
refs.local = require('./refs-local')(arg)

0 commit comments

Comments
 (0)