1 Reply Latest reply on Nov 27, 2008 2:12 AM by kamil02

    uncompress folder

    kamil02
      Hi there!

      I am playing with the uncompress function of air and javascript.
      I have done the "ByteArray example: Reading a .zip file" training ( link) and everythings works fine.

      Now i am trying to uncompress a zip file including folders.
      The Reading a .zip file example finds the correct files but after finding a folder it gets a problem, i think its becoause it is reading the wrong bytes.

      Anyone got an idea of how to uncompress folders? Google didnt help at all.

      Here is a sample code where i think the error occures:


      quote:


      while (zStream.position < zfile.size) {
      // read fixed metadata portion of local file header
      zStream.readBytes(bytes, 0, 30);

      bytes.position = 0;
      signature = bytes.readInt();
      // if no longer reading data files, quit
      if (signature != 0x04034b50) {
      break;
      }

      bytes.position = 8;
      compMethod = bytes.readByte(); // store compression method (8 == Deflate)

      offset = 0; // stores length of variable portion of metadata
      bytes.position = 26; // offset to file name length
      flNameLength = bytes.readShort(); // store file name
      offset += flNameLength; // add length of file name
      bytes.position = 28; // offset to extra field length
      xfldLength = bytes.readShort();
      offset += xfldLength; // add length of extra field
      // if a folder is found offset seems to have the size of all files inside the folder


      // read variable length bytes between fixed-length header and compressed file data
      zStream.readBytes(bytes, 30, offset);

      bytes.position = 30;
      fileName = bytes.readUTFBytes(flNameLength); // read file name
      output += fileName + "<br />"; // write file name to text area
      bytes.position = 18;
      compSize = bytes.readUnsignedInt(); // store size of compressed portion
      output += "\tCompressed size is: " + compSize + '<br />';
      bytes.position = 22; // offset to uncompressed size
      uncompSize = bytes.readUnsignedInt(); // store uncompressed size
      output += "\tUncompressed size is: " + uncompSize + '<br />';

      // read compressed file to offset 0 of bytes; for uncompressed files
      // the compressed and uncompressed size is the same
      // if a folder is found the compSize is 0
      zStream.readBytes(bytes, 0, compSize);

      if (compMethod == 8) {// if file is compressed, uncompress
      bytes.uncompress(air.CompressionAlgorithm.DEFLATE);
      }
      }



      thx!