Yup. It’s not working as I thought.

I just did this:

NodeStreamParams.as:
package com.printui.utils
{
        public class NodeStreamParam
        {
        public function NodeStreamParam(type:String,streamFiles:Boolean)
        {
            this.type = type;
            this.streamFiles = streamFiles;
        }
                public static const NODE_BUFFER:String = "nodeBuffer";
                public var type:String;
                public var streamFiles:Boolean;
        }
}

JSZip.as:
package com.printui.utils
{
        import stream.Stream;

        public class JSZip
        {
                public function generateNodeStream(nsp:NodeStreamParam):Stream{
                        return null;
                }
        }
    
}
Usage:
                        var jszip:* = require("jszip");

                        var zip:JSZip = new jszip();
                        var name:String = folderToZip.name;
                        recursiveAdd(folderToZip,zip,"");
                        var promise:Promise = new 
Promise(function(resolve:*,reject:*):void{
                                var zipFile:File = 
destinationFolder.resolvePath(folderToZip.name + ".zip");
                                var zipStream:Stream  = 
zip.generateNodeStream(new 
NodeStreamParam(NodeStreamParam.NODE_BUFFER,true)).pipe(
                                fs.createWriteStream(zipFile.nativePath));

Output:

;u(Kt,uT);fs=require('fs');require('stream');function vT(){}function 
wT(a,b){var c=new (require(Az));xT(a,c,e);return new Promise(function(d,f){var 
h=b.ba(a.name+Zc),k=c.Dr(new uT(zA,!0)).pipe(fs.createWriteStream(h.nativePath))

I have not tested this, but it’s pretty clear to me that this will not work.

new uT(zA,!0) should be fine because the constructor is defined like this:
function uT(a,b){this.type=a;this.streamFiles=b}

However, c looks totally borked:
var c=new (require(Az)). That’s ok because Az is defined as ‘aszip’.
However c.Dr(new uT(zA,!0)) is not gonna work because jszip does not have a Dr 
method.

Here’s the full contents of the non-minified function for reference:
  var /** @type {Function} */ __localFn0__ = function(resolve, reject) {
    var /** @type {Function} */ __localFn0__ = function() {
      console.log(zipFile.name + " written.");
      resolve(zipFile);
    }
    var /** @type {Function} */ __localFn1__ = function() {
      console.log("zip error");
      reject("error");
    }
    var /** @type {com.printui.utils.File} */ zipFile = 
destinationFolder.resolvePath(folderToZip.name + ".zip");
    var /** @type {stream.Stream} */ zipStream = zip.generateNodeStream(new 
com.printui.utils.NodeStreamParam(com.printui.utils.NodeStreamParam.NODE_BUFFER,
 true)).pipe(fs.createWriteStream(zipFile.nativePath));
    zipStream.on('finish', __localFn0__);
    zipStream.on('error', __localFn1__);
  }
  var /** @type {*} */ jszip = require("jszip");
  var /** @type {com.printui.utils.JSZip} */ zip = new jszip();
  var /** @type {string} */ name = folderToZip.name;
  com.printui.utils.FolderZipper.recursiveAdd(folderToZip, zip, "");
  var /** @type {Promise} */ promise = new Promise(__localFn0__);
  return promise;


On Dec 12, 2016, at 9:56 AM, Harbs <harbs.li...@gmail.com> wrote:

> I thought I tried something similar and declaring the types did not help 
> (i.e. the externs were not generated), but maybe I did something wrong.

Reply via email to