This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds wiring for a progress bar Passes the progress bar option for tranfers over http. Progress is shown for your payload being streamed upto the server. There is a pause. Then you get your list of files. * feat: Support specify hash algorithm in files.add (#597) * support support specify hash alg * Add test for add with --hash option. Pass raw cid/multihash to ipfs object get/data * Allow object get/data to accept CID * Var naming tweaks from review * feat: track progress events * tesT: add more tests * fix: tidy up tests * feat: send errors as trailer headers * fix: remove .only from tests * feat: signal error on reponse stream if x-stream-error * test: adding tests for trailer header errors * chore: update interface-ipfs-core * chore: upgrade to latest interface-ipfs-core
- Loading branch information
Showing
8 changed files
with
201 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
const Transform = require('readable-stream').Transform | ||
|
||
/* | ||
A transform stream to track progress events on file upload | ||
When the progress flag is passed to the HTTP api, the stream | ||
emits progress events like such: | ||
{ | ||
Name string | ||
Hash string `json:",omitempty"` | ||
Bytes int64 `json:",omitempty"` | ||
Size string `json:",omitempty"` | ||
} | ||
This class will take care of detecting such | ||
events and calling the associated track method | ||
with the bytes sent so far as parameter. It will | ||
also skip them from the stream, emitting only | ||
when the final object has been uploaded and we | ||
got a hash. | ||
*/ | ||
class ProgressStream extends Transform { | ||
constructor (opts) { | ||
opts = Object.assign(opts || {}, { objectMode: true }) | ||
super(opts) | ||
this._track = opts.track || (() => {}) | ||
} | ||
|
||
static fromStream (track, stream) { | ||
const prog = new ProgressStream({ track }) | ||
return stream.pipe(prog) | ||
} | ||
|
||
_transform (chunk, encoding, callback) { | ||
if (chunk && | ||
typeof chunk.Bytes !== 'undefined' && | ||
typeof chunk.Hash === 'undefined') { | ||
this._track(chunk.Bytes) | ||
return callback() | ||
} | ||
|
||
callback(null, chunk) | ||
} | ||
} | ||
|
||
module.exports = ProgressStream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters