[need help] nsIZipReader can't open zip file - Mozilla

This is a discussion on [need help] nsIZipReader can't open zip file - Mozilla ; Hi, there, The following simple code just didn't work... I'm so confusing, var nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker; 1"].createInstance(nsIFilePicker); var fileMode, winTitle; fileMode = nsIFilePicker.modeOpen; winTitle = "test"; fp.init(window, winTitle, fileMode); fp.appendFilters(nsIFilePicker.filterAll); var rv = fp.show(); if (rv ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: [need help] nsIZipReader can't open zip file

  1. [need help] nsIZipReader can't open zip file

    Hi, there,

    The following simple code just didn't work... I'm so confusing,

    var nsIFilePicker = Components.interfaces.nsIFilePicker;
    var fp = Components.classes["@mozilla.org/filepicker;
    1"].createInstance(nsIFilePicker);
    var fileMode, winTitle;
    fileMode = nsIFilePicker.modeOpen;
    winTitle = "test";
    fp.init(window, winTitle, fileMode);
    fp.appendFilters(nsIFilePicker.filterAll);
    var rv = fp.show();
    if (rv == nsIFilePicker.returnOK){
    print (fp.file.path);
    }

    Just pickup any zip file and run the following lines:

    var zipR = Components.classes["@mozilla.org/libjar/zip-reader;
    1"].createInstance(Components.interfaces.nsIZipReader );
    zipR.open(fp.file)

    The error message was:
    NS_ERROR_INVALID_POINTER on line 2: Component returned failure code:
    0x80004003 (NS_ERROR_INVALID_POINTER) [nsIZipReader.open]

    Any idea about why it didn't work?

    Thanks.
    Calvin

  2. Re: [need help] nsIZipReader can't open zip file

    Calvin Liu wrote:
    > Hi, there,
    >
    > The following simple code just didn't work... I'm so confusing,
    >
    > var nsIFilePicker = Components.interfaces.nsIFilePicker;
    > var fp =
    > Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
    >
    > var fileMode, winTitle;
    > fileMode = nsIFilePicker.modeOpen;
    > winTitle = "test";
    > fp.init(window, winTitle, fileMode);
    > fp.appendFilters(nsIFilePicker.filterAll);
    > var rv = fp.show();
    > if (rv == nsIFilePicker.returnOK){
    > print (fp.file.path);
    > }
    >
    > Just pickup any zip file and run the following lines:
    >
    > var zipR =
    > Components.classes["@mozilla.org/libjar/zip-reader;1"].createInstance(Components.interfaces.nsIZipReader );
    >
    > zipR.open(fp.file)
    >
    > The error message was:
    > NS_ERROR_INVALID_POINTER on line 2: Component returned failure code:
    > 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIZipReader.open]
    >
    > Any idea about why it didn't work?
    >
    > Thanks.
    > Calvin


    When asking for support please always try to provide the version and
    application that you are testing in. In this case I suspect you might be
    trying this code in gecko 1.8 (firefox 2) where you need to use the init
    method on nsIZipReader

    Dave


  3. Re: [need help] nsIZipReader can't open zip file

    Hi, Dave,

    Thanks for the feedback. Yes, it is for firefox 2.x and I figured it
    out that for firefox 2, I need to call init() at first. (Weird that
    it's not documented anywhere. I got the answer when looking into the
    zipR object in the javascript shell.)

    But there's still problem for the following code:

    //got zipR initialized and opened, tested good

    zipR.init(fp.file);
    zipR.open(fp.file);
    zipR.test(null);

    // now get data
    var coll = zipR.findEntries('*');
    while (coll.hasMoreElements()) {
    var obj = coll.getNext();
    obj.QueryInterface(Components.interfaces.nsIZipEnt ry); //Do I have to
    do this?
    print(obj.name+', '+obj.name.split('/')+'\n');
    // zipR.extract(obj, toFile); //toFile is another nsIFile object,
    anyway this will fail
    }

    When I tried to run the code above I got another error like this:
    sm [DEBUG]: myService.run() error: [Exception... "Component returned
    failure code: 0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
    [nsIZipReader.extract]" nsresult: "0x80520006
    (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)" location: "JS frame ::
    chrome://path/to/myService.js :: anonymous :: line 722" data: no]

    And I already set the compress mode to NONE (0) in zipWriter (in
    firefox 3) when creating that zip file.

    I suppose I should be able to create a zip file in firefox 3 and read
    it in firefox 2, right?

    Thanks.
    Calvin


    On 30-Apr-08, at 2:39 AM, Dave Townsend wrote:

    > Calvin Liu wrote:
    >> Hi, there,
    >>
    >> The following simple code just didn't work... I'm so confusing,
    >>
    >> var nsIFilePicker = Components.interfaces.nsIFilePicker;
    >> var fp =
    >> Components.classes["@mozilla.org/filepicker;
    >> 1"].createInstance(nsIFilePicker);
    >>
    >> var fileMode, winTitle;
    >> fileMode = nsIFilePicker.modeOpen;
    >> winTitle = "test";
    >> fp.init(window, winTitle, fileMode);
    >> fp.appendFilters(nsIFilePicker.filterAll);
    >> var rv = fp.show();
    >> if (rv == nsIFilePicker.returnOK){
    >> print (fp.file.path);
    >> }
    >>
    >> Just pickup any zip file and run the following lines:
    >>
    >> var zipR =
    >> Components.classes["@mozilla.org/libjar/zip-reader;
    >> 1"].createInstance(Components.interfaces.nsIZipReader );
    >>
    >> zipR.open(fp.file)
    >>
    >> The error message was:
    >> NS_ERROR_INVALID_POINTER on line 2: Component returned failure code:
    >> 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIZipReader.open]
    >>
    >> Any idea about why it didn't work?
    >>
    >> Thanks.
    >> Calvin

    >
    > When asking for support please always try to provide the version and
    > application that you are testing in. In this case I suspect you
    > might be
    > trying this code in gecko 1.8 (firefox 2) where you need to use the
    > init
    > method on nsIZipReader
    >
    > Dave
    >
    > _______________________________________________
    > dev-extensions mailing list
    > dev-extensions@lists.mozilla.org
    > https://lists.mozilla.org/listinfo/dev-extensions
    >
    >



  4. Re: [need help] nsIZipReader can't open zip file

    Calvin Liu wrote:
    > Hi, Dave,
    >
    > Thanks for the feedback. Yes, it is for firefox 2.x and I figured it out
    > that for firefox 2, I need to call init() at first. (Weird that it's not
    > documented anywhere. I got the answer when looking into the zipR object
    > in the javascript shell.)
    >
    > But there's still problem for the following code:
    >
    > //got zipR initialized and opened, tested good
    >
    > zipR.init(fp.file);
    > zipR.open(fp.file);
    > zipR.test(null);
    >
    > // now get data
    > var coll = zipR.findEntries('*');
    > while (coll.hasMoreElements()) {
    > var obj = coll.getNext();
    > obj.QueryInterface(Components.interfaces.nsIZipEnt ry); //Do I have to do
    > this?
    > print(obj.name+', '+obj.name.split('/')+'\n');
    > // zipR.extract(obj, toFile); //toFile is another nsIFile object, anyway
    > this will fail
    > }



    Please read the interface documentation for the version you are using.
    extract takes a string path as its first argument.

    http://mxr-test.landfill.bugzilla.or...IZipReader.idl


+ Reply to Thread