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

Commit 1018e7d

Browse files
committed
fix: prevent returning from http write command early
Also splits bufferStream out into it's own module as sometimes it's useful to have a pull stream that emits a known number of buffers. License: MIT Signed-off-by: achingbrain <alex@achingbrain.net>
1 parent 36bde9d commit 1018e7d

File tree

12 files changed

+17
-71
lines changed

12 files changed

+17
-71
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"detect-webworker": "^1.0.0",
4444
"dirty-chai": "^2.0.1",
4545
"ipfs": "~0.30.0",
46+
"pull-buffer-stream": "^1.0.0",
4647
"safe-buffer": "^5.1.1",
4748
"tmp": "~0.0.33"
4849
},

src/core/utils/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports = {
88
countStreamBytes: require('./count-stream-bytes'),
99
createLock: require('./create-lock'),
1010
createNode: require('./create-node'),
11-
endPullStream: require('./end-pull-stream'),
1211
formatCid: require('./format-cid'),
1312
limitStreamBytes: require('./limit-stream-bytes'),
1413
loadNode: require('./load-node'),

src/core/utils/limit-stream-bytes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict'
22

33
const asyncMap = require('pull-stream/throughs/async-map')
4-
const endPullStream = require('./end-pull-stream')
54

65
const limitStreamBytes = (limit) => {
76
let bytesRead = 0
87

98
return asyncMap((buffer, cb) => {
109
if (bytesRead > limit) {
11-
endPullStream(cb)
10+
cb(true) // eslint-disable-line standard/no-callback-literal
1211
}
1312

1413
// If we only need to return part of this buffer, slice it to make it smaller

src/core/write/update-tree.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const updateTree = (ipfs, root, fileSize, streamStart, streamEnd, source, option
4242
nodeStart: streamPosition,
4343
nodeEnd: fileSize
4444
}, findDAGNodesWithRequestedData),
45-
paramap(updateNodeData(source)),
45+
asyncMap(updateNodeData(source)),
4646
filter(Boolean),
4747
asyncMap((link, next) => {
4848
if (!link.parent || link.index === undefined) {
@@ -179,7 +179,11 @@ const updateTree = (ipfs, root, fileSize, streamStart, streamEnd, source, option
179179
sourceEnd = undefined
180180
}
181181

182-
sourceData.copy(newData, targetStart, sourceStart, sourceEnd)
182+
try {
183+
sourceData.copy(newData, targetStart, sourceStart, sourceEnd)
184+
} catch (error) {
185+
return cb(error)
186+
}
183187

184188
cb(null, new UnixFs(meta.type, newData).marshal())
185189
},

src/http/write.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const mfsWrite = (api) => {
6363
strategy,
6464
flush
6565
})
66+
.then(() => reply())
6667
.catch(error => {
6768
reply({
6869
Message: error.message,
@@ -79,18 +80,6 @@ const mfsWrite = (api) => {
7980
Type: 'error'
8081
}).code(500).takeover()
8182
})
82-
83-
parser.on('end', () => {
84-
if (!filesParsed) {
85-
return reply({
86-
Message: "File argument 'data' is required.",
87-
Code: 0,
88-
Type: 'error'
89-
}).code(400).takeover()
90-
}
91-
92-
reply()
93-
})
9483
},
9584
validate: {
9685
options: {

test/cp.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
const chai = require('chai')
55
chai.use(require('dirty-chai'))
66
const expect = chai.expect
7+
const bufferStream = require('pull-buffer-stream')
78

89
const {
9-
createMfs,
10-
bufferStream
10+
createMfs
1111
} = require('./helpers')
1212

1313
describe('cp', function () {

test/helpers/buffer-stream.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

test/helpers/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const createMfs = promisify((cb) => {
3838

3939
module.exports = {
4040
createMfs,
41-
bufferStream: require('./buffer-stream'),
4241
collectLeafCids: require('./collect-leaf-cids'),
4342
EMPTY_DIRECTORY_HASH: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn',
4443
EMPTY_DIRECTORY_HASH_BASE32: 'bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354'

test/mv.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
const chai = require('chai')
55
chai.use(require('dirty-chai'))
66
const expect = chai.expect
7+
const bufferStream = require('pull-buffer-stream')
78
const {
8-
createMfs,
9-
bufferStream
9+
createMfs
1010
} = require('./helpers')
1111

1212
describe('mv', function () {

test/read.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ chai.use(require('dirty-chai'))
66
const expect = chai.expect
77
const path = require('path')
88
const loadFixture = require('aegir/fixtures')
9-
const {
10-
bufferStream
11-
} = require('./helpers')
9+
const bufferStream = require('pull-buffer-stream')
1210
const pull = require('pull-stream/pull')
1311
const collect = require('pull-stream/sinks/collect')
1412
const {

test/rm.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
const chai = require('chai')
55
chai.use(require('dirty-chai'))
66
const expect = chai.expect
7+
const bufferStream = require('pull-buffer-stream')
78
const {
8-
createMfs,
9-
bufferStream
9+
createMfs
1010
} = require('./helpers')
1111
const {
1212
FILE_SEPARATOR

test/write.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const path = require('path')
88
const loadFixture = require('aegir/fixtures')
99
const isNode = require('detect-node')
1010
const values = require('pull-stream/sources/values')
11+
const bufferStream = require('pull-buffer-stream')
1112
const {
12-
bufferStream,
1313
collectLeafCids,
1414
createMfs
1515
} = require('./helpers')

0 commit comments

Comments
 (0)