Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: progress bar flakiness #1042

Merged
merged 2 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ module.exports = {
const ipfs = argv.ipfs

let list = []
let currentBytes = 0

waterfall([
(next) => glob(path.join(inPath, '/**/*'), next),
(globResult, next) => {
Expand All @@ -216,8 +214,7 @@ module.exports = {
if (argv.progress) {
const bar = createProgressBar(totalBytes)
options.progress = function (byteLength) {
currentBytes += byteLength
bar.tick(byteLength, {progress: byteman(currentBytes, 2, 'MB')})
bar.update(byteLength / totalBytes, {progress: byteman(byteLength, 2, 'MB')})
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module.exports = function files (self) {
shardSplitThreshold: self._options.EXPERIMENTAL.sharding ? 1000 : Infinity
}, options)

let total = 0
let prog = opts.progress || (() => {})
const progress = (bytes) => {
total += bytes
prog(total)
}

opts.progress = progress
return pull(
pull.map(normalizeContent),
pull.flatten(),
Expand Down Expand Up @@ -65,18 +73,9 @@ module.exports = function files (self) {
return callback(new Error('Invalid arguments, data must be an object, Buffer or readable stream'))
}

let total = 0
let prog = options.progress || (() => {})
const progress = (bytes) => {
total += bytes
prog(total)
}

options.progress = progress
pull(
pull.values(normalizeContent(data)),
importer(self._ipldResolver, options),
pull.asyncMap(prepareFile.bind(null, self, options)),
pull.values([data]),
createAddPullStream(options),
sort((a, b) => {
if (a.path < b.path) return 1
if (a.path > b.path) return -1
Expand Down
4 changes: 1 addition & 3 deletions src/http/api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ exports.add = {
})

const replyStream = pushable()
let total = 0
const progressHandler = (bytes) => {
total += bytes
replyStream.push({ Bytes: total })
replyStream.push({ Bytes: bytes })
}

const options = {
Expand Down