diff --git a/js/Dweb.js b/js/Dweb.js index 74e5207..a873cf5 100644 --- a/js/Dweb.js +++ b/js/Dweb.js @@ -57,7 +57,7 @@ exports.utils.mergeTypedArraysUnsafe = function(a, b) { // Take care of inabilit }; //TODO-STREAM, use this code and return stream from p_rawfetch that this can be applied to -exports.utils.p_streamToBuffer = function(stream, mimeType) { +exports.utils.p_streamToBuffer = function(stream, verbose) { // resolve to a promise that returns a stream. // Note this comes form one example ... // There is another example https://github.com/ipfs/js-ipfs/blob/master/examples/exchange-files-in-browser/public/js/app.js#L102 very different @@ -65,8 +65,8 @@ exports.utils.p_streamToBuffer = function(stream, mimeType) { try { let chunks = []; stream - .on('data', (chunk) => chunks.push(chunk)) - .once('end', () => resolve(Buffer.concat(chunks))) + .on('data', (chunk) => { if (verbose) console.log('on', chunk.length); chunks.push(chunk); }) + .once('end', () => { if (verbose) console.log('end chunks', chunks.length); resolve(Buffer.concat(chunks)); }) .on('error', (err) => { // Note error behavior untested currently console.log("Error event in p_streamToBuffer",err); reject(new Dweb.errors.TransportError('Error in stream')) @@ -79,7 +79,8 @@ exports.utils.p_streamToBuffer = function(stream, mimeType) { }) } //TODO-STREAM, use this code and return stream from p_rawfetch that this can be applied to -exports.utils.p_streamToBlob = function(stream, mimeType) { +//TODO-STREAM debugging in streamToBuffer above, copy to here when fixed above +exports.utils.p_streamToBlob = function(stream, mimeType, verbose) { // resolve to a promise that returns a stream - currently untested as using Buffer return new Promise((resolve, reject) => { try { diff --git a/js/TransportIPFS.js b/js/TransportIPFS.js index 45f373b..e058ac5 100644 --- a/js/TransportIPFS.js +++ b/js/TransportIPFS.js @@ -331,7 +331,7 @@ class TransportIPFS extends Transport { if (verbose) console.log("CID=",cid) //return this.promisified.ipfs.block.get(cid).then((result) => result.data) // OLD way, works below 250k bytes, where files.cat doesnt ! return this.ipfs.files.cat(cid) - .then((stream) => Dweb.utils.p_streamToBuffer(stream)) + .then((stream) => Dweb.utils.p_streamToBuffer(stream, verbose)) .then((data)=> { if (verbose) console.log("fetched ",data.length); return data; }) .catch((err) => { console.log("Caught misc error in TransportIPFS.p_rawfetch", err);