* 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)
| 2843 | * @return Promise the promise for the accumulation. |
| 2844 | */ |
| 2845 | function 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. |
no test coverage detected