MCPcopy Index your code
hub / github.com/hoothin/UserScripts / accumulate

Function accumulate

Picviewer CE+/dist.user.js:2845–2873  ·  view source on GitHub ↗

* Listen a StreamHelper, accumulate its content and concatenate it into a * complete block. * @param {StreamHelper} helper the helper to use. * @param {Function} updateCallback a callback called on each update. Called * with one arg : * - the metadata linked to the update received. * @return P

(helper, updateCallback)

Source from the content-addressed store, hash-verified

2843 * @return Promise the promise for the accumulation.
2844 */
2845function accumulate(helper, updateCallback) {
2846 return new external.Promise(function (resolve, reject){
2847 var dataArray = [];
2848 var chunkType = helper._internalType,
2849 resultType = helper._outputType,
2850 mimeType = helper._mimeType;
2851 helper
2852 .on('data', function (data, meta) {
2853 dataArray.push(data);
2854 if(updateCallback) {
2855 updateCallback(meta);
2856 }
2857 })
2858 .on('error', function(err) {
2859 dataArray = [];
2860 reject(err);
2861 })
2862 .on('end', function (){
2863 try {
2864 var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
2865 resolve(result);
2866 } catch (e) {
2867 reject(e);
2868 }
2869 dataArray = [];
2870 })
2871 .resume();
2872 });
2873}
2874
2875/**
2876 * An helper to easily use workers outside of JSZip.

Callers 1

dist.user.jsFile · 0.70

Calls 4

rejectFunction · 0.70
transformZipOutputFunction · 0.70
concatFunction · 0.70
resolveFunction · 0.70

Tested by

no test coverage detected