ASZip0.2版本解决中文文件名乱码问题

Stella981
• 阅读 676

ASZip文件库是开源的AS3版–Zip压缩算法,具体示例应用可见http://code.google.com/p/aszip/。目前的最新版本是0.2版。最近在项目中需要用到该第三方类库来支持Flash对图片文件的批量打包上传。由于是外国友人写的,所以对中文命名的图片文件进行压缩时,就会报错,只能支持用非中文的命名的图片文件。

下面是我在作者原有代码的基础上做了些改进,使其能良好的支持中英文命名的文件,进而对文件打包压缩。

    /**  


  
  
  
  
 
  
 
  
 
   
   
    * This class lets you generate zip files in AS3  


  
  
  
  
 
  
 
  
 
   
   
    * AS3 implementation of the following PHP script :  


  
  
  
  
 
  
 
  
 
   
   
    * http://www.zend.com/zend/spotlight/creating-zip-files1.php?article=creating-zip-files1&kind=sl&id=274&open=1&anc=0&view=1  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * @author Thibault Imbert (bytearray.org)  


  
  
  
  
 
  
 
  
 
   
   
    * @usage Compression methods for the files :  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * CompressionMethod.NONE = no compression is applied  


  
  
  
  
 
  
 
  
 
   
   
    * CompressionMethod.GZIP = native GZIP compression is applied  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * first parameter : compression method  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * var myZip:ASZIP = new ASZIP ( CompressionMethod.GZIP );  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * @version 0.1 First release  


  
  
  
  
 
  
 
  
 
   
   
    * @version 0.2 ASZip.saveZIP method added  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    package org.aszip.zip  


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    import flash.accessibility.Accessibility;  


  
  
  
  
 
  
 
  
 
   
   
    import flash.utils.ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    import flash.utils.Endian;  


  
  
  
  
 
  
 
  
 
   
   
    import flash.net.URLRequest;  


  
  
  
  
 
  
 
  
 
   
   
    import flash.net.URLRequestHeader;  


  
  
  
  
 
  
 
  
 
   
   
    import flash.net.URLRequestMethod;  


  
  
  
  
 
  
 
  
 
   
   
    import flash.net.navigateToURL;  


  
  
  
  
 
  
 
  
 
   
   
    import org.aszip.saving.Method;  


  
  
  
  
 
  
 
  
 
   
   
    import org.aszip.compression.CompressionMethod;  


  
  
  
  
 
  
 
  
 
   
   
    import org.aszip.crc.CRC32;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * The ASZip class represents a Zip file  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    public class ASZip  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * The compressed data buffer  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    private var compressedData:ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * The central directory  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    private var centralDirectory:ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * The central index  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    private var oldOffset:Number  


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * Number of directories in the zip  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    private var nbDirectory:Array;  


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * The final zip stream  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    private var output:ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * The compression method used  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    private var compressionMethod:String;  


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * The comment string  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    private var comment:String;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * Lets you create a Zip file  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * @param pCompression Compression method  


  
  
  
  
 
  
 
  
 
   
   
    * @example  


  
  
  
  
 
  
 
  
 
   
   
    * This example shows how to create a valid ZIP file :  


  
  
  
  
 
  
 
  
 
   
   
    * <div>  


  
  
  
  
 
  
 
  
 
   
   
    * <pre>  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * var myZip:ASZip = new ASZip ( CompressionMethod.GZIP );  


  
  
  
  
 
  
 
  
 
   
   
    * </pre>  


  
  
  
  
 
  
 
  
 
   
   
    * </div>  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    public function ASZip ( pCompression:String='GZIP' )  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    compressedData = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    centralDirectory = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    output = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    nbDirectory = new Array  


  
  
  
  
 
  
 
  
 
   
   
    comment = new String;;  


  
  
  
  
 
  
 
  
 
   
   
    oldOffset = 0;  


  
  
  
  
 
  
 
  
 
   
   
    compressionMethod = pCompression;  


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * Lets you create a directory for the current Zip  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * @param directoryName Name of the directory  


  
  
  
  
 
  
 
  
 
   
   
    * @example  


  
  
  
  
 
  
 
  
 
   
   
    * This example shows how to create a directory and subdirectory :  


  
  
  
  
 
  
 
  
 
   
   
    * <div>  


  
  
  
  
 
  
 
  
 
   
   
    * <pre>  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * myZip.addDirectory ( "images" );  


  
  
  
  
 
  
 
  
 
   
   
    * myZip.addDirectory ( "images/funk" );  


  
  
  
  
 
  
 
  
 
   
   
    * </pre>  


  
  
  
  
 
  
 
  
 
   
   
    * </div>  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    public function addDirectory ( directoryName:String ):void  


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    directoryName = directoryName.split ('\\').join ('/');  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    var feedArrayRow:ByteArray = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.endian = Endian.LITTLE_ENDIAN;  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( 0x04034b50 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( 0x000a );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( unixToDos ( new Date().getTime() ) );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt (0);  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt (0);  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt (0);  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( directoryName.length );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUTFBytes ( directoryName );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    compressedData.writeBytes ( feedArrayRow );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    var newOffset:int = this.compressedData.length;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    // Directory header  


  
  
  
  
 
  
 
  
 
   
   
    var addCentralRecord:ByteArray = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.endian = Endian.LITTLE_ENDIAN;  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( 0x02014b50 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0x000a );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( 0x00000000 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( directoryName.length );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( 16 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( this.oldOffset );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    this.oldOffset = newOffset;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUTFBytes (directoryName);  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    this.nbDirectory.push ( addCentralRecord );  


  
  
  
  
 
  
 
  
 
   
   
    this.centralDirectory.writeBytes ( addCentralRecord );  


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * Lets you add a file into a specific directory  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * @param pBytes File stream  


  
  
  
  
 
  
 
  
 
   
   
    * @param pDirectory Directory name  


  
  
  
  
 
  
 
  
 
   
   
    * @example  


  
  
  
  
 
  
 
  
 
   
   
    * This example shows how to add files into directories :  


  
  
  
  
 
  
 
  
 
   
   
    * <div>  


  
  
  
  
 
  
 
  
 
   
   
    * <pre>  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * myZip.addFile ( imageByteArray, "images/image.jpg" );  


  
  
  
  
 
  
 
  
 
   
   
    * myZip.addFile ( imageByteArray, "images/funk/image.jpg" );  


  
  
  
  
 
  
 
  
 
   
   
    * </pre>  


  
  
  
  
 
  
 
  
 
   
   
    * </div>  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    public function addFile ( pBytes:ByteArray, pDirectory:String ):void  


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    pDirectory = pDirectory.split ('\\').join ('/');  


  
  
  
  
 
  
 
  
 
   
   
    var pDirectory_byte:* = new ByteArray();  


  
  
  
  
 
  
 
  
 
   
   
    pDirectory_byte.writeMultiByte(pDirectory, "GBK");  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    var feedArrayRow:ByteArray = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.endian = Endian.LITTLE_ENDIAN;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    // Local File Header  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( 0x04034b50 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( 0x0014 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    // File is deflated  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( this.compressionMethod == CompressionMethod.GZIP ? 0x0008 : 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( unixToDos ( new Date().getTime() ) );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    var uncompressedLength:Number = pBytes.length;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    // CRC32 checksum  


  
  
  
  
 
  
 
  
 
   
   
    var crc:CRC32 = new CRC32;  


  
  
  
  
 
  
 
  
 
   
   
    crc.generateCRC32 ( pBytes );  


  
  
  
  
 
  
 
  
 
   
   
    var compression:int = crc.getCRC32();  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    // If GZIP compression  


  
  
  
  
 
  
 
  
 
   
   
    if ( compressionMethod == CompressionMethod.GZIP )  


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    pBytes.compress();  


  
  
  
  
 
  
 
  
 
   
   
    var copy:ByteArray = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    copy.writeBytes ( pBytes, 0, pBytes.length - 4 );  


  
  
  
  
 
  
 
  
 
   
   
    var finalCopy:ByteArray = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    finalCopy.writeBytes ( copy, 2 );  


  
  
  
  
 
  
 
  
 
   
   
    pBytes = finalCopy;  


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    var compressedLength:int = pBytes.length;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( compression );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( compressedLength );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( uncompressedLength );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( pDirectory_byte.length );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeBytes ( pDirectory_byte );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeBytes ( pBytes );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    // Data Descriptor  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( compression );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( compressedLength );  


  
  
  
  
 
  
 
  
 
   
   
    feedArrayRow.writeUnsignedInt ( uncompressedLength );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    compressedData.writeBytes ( feedArrayRow );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    var newOffset:int = compressedData.length;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    // File header  


  
  
  
  
 
  
 
  
 
   
   
    var addCentralRecord:ByteArray = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.endian = Endian.LITTLE_ENDIAN;  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( 0x02014b50 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0x0014 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( this.compressionMethod == CompressionMethod.GZIP ? 0x0008 : 0x0000 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( unixToDos ( new Date().getTime() ) );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( compression );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( compressedLength );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( uncompressedLength );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort(pDirectory_byte.length);  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeShort ( 0 );  


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt( 32 );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeUnsignedInt ( this.oldOffset );  


  
  
  
  
 
  
 
  
 
   
   
    this.oldOffset = newOffset;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    addCentralRecord.writeBytes ( pDirectory_byte );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    this.nbDirectory.push ( addCentralRecord );  


  
  
  
  
 
  
 
  
 
   
   
    this.centralDirectory.writeBytes ( addCentralRecord );  


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * Lets you add a comment into the Zip file  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * @param pComment The comment string to add  


  
  
  
  
 
  
 
  
 
   
   
    * @example  


  
  
  
  
 
  
 
  
 
   
   
    * This example shows how to add a comment for the current zip :  


  
  
  
  
 
  
 
  
 
   
   
    * <div><pre>myZip.addComment ( "Hello there !");</pre></div>  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    public function addComment ( pComment:String ):void  


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    comment = pComment;  


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    /**  


  
  
  
  
 
  
 
  
 
   
   
    * Lets you finalize and save the ZIP file and make it available for download  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * @param pMethod Can be se to Method.LOCAL, the saveZIP will return the ZIP ByteArray. When Method.REMOTE is passed, just specify the path to the create.php file  


  
  
  
  
 
  
 
  
 
   
   
    * @param pURL The url of the create.php file  


  
  
  
  
 
  
 
  
 
   
   
    * @param pDownload Lets you specify the way the ZIP is going to be available. Use Download.INLINE if you want the ZIP to be directly opened, use Download.ATTACHMENT if you want to make it available with a save-as dialog box  


  
  
  
  
 
  
 
  
 
   
   
    * @param pName The name of the ZIP, only available when Method.REMOTE is used  


  
  
  
  
 
  
 
  
 
   
   
    * @return The ByteArray ZIP when Method.LOCAL is used, otherwise the method returns null  


  
  
  
  
 
  
 
  
 
   
   
    * @example  


  
  
  
  
 
  
 
  
 
   
   
    * This example shows how to save the ZIP with a download dialog-box :  


  
  
  
  
 
  
 
  
 
   
   
    * <div>  


  
  
  
  
 
  
 
  
 
   
   
    * <pre>  


  
  
  
  
 
  
 
  
 
   
   
    *  


  
  
  
  
 
  
 
  
 
   
   
    * myZIP.saveZIP ( Method.REMOTE, 'create.php', Download.ATTACHMENT, 'archive.zip' );  


  
  
  
  
 
  
 
  
 
   
   
    * </pre>  


  
  
  
  
 
  
 
  
 
   
   
    * </div>  


  
  
  
  
 
  
 
  
 
   
   
    */  


  
  
  
  
 
  
 
  
 
   
   
    public function saveZIP ( pMethod:String, pURL:String='', pDownload:String='inline', pName:String='archive.zip' ):*  


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    output = new ByteArray;  


  
  
  
  
 
  
 
  
 
   
   
    output.endian = Endian.LITTLE_ENDIAN;  


  
  
  
  
 
  
 
  
 
   
   
    output.writeBytes ( this.compressedData );  


  
  
  
  
 
  
 
  
 
   
   
    output.writeBytes ( this.centralDirectory );  


  
  
  
  
 
  
 
  
 
   
   
    output.writeUnsignedInt ( 0x06054b50 );  


  
  
  
  
 
  
 
  
 
   
   
    output.writeUnsignedInt ( 0x00000000 );  


  
  
  
  
 
  
 
  
 
   
   
    output.writeShort ( this.nbDirectory.length );  


  
  
  
  
 
  
 
  
 
   
   
    output.writeShort ( this.nbDirectory.length );  


  
  
  
  
 
  
 
  
 
   
   
    output.writeUnsignedInt ( this.centralDirectory.length );  


  
  
  
  
 
  
 
  
 
   
   
    output.writeUnsignedInt ( this.compressedData.length );  


  
  
  
  
 
  
 
  
 
   
   
    var _loc_3:* = new ByteArray();  


  
  
  
  
 
  
 
  
 
   
   
    _loc_3.writeMultiByte(comment, "GBK");  


  
  
  
  
 
  
 
  
 
   
   
    output.writeShort(_loc_3.length);  


  
  
  
  
 
  
 
  
 
   
   
    output.writeBytes(_loc_3);  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    if ( pMethod == Method.LOCAL ) return output;  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");  


  
  
  
  
 
  
 
  
 
   
   
    var myRequest:URLRequest = new URLRequest ( pURL+'?name='+pName+'&amp;method='+pDownload );  


  
  
  
  
 
  
 
  
 
   
   
    myRequest.requestHeaders.push (header);  


  
  
  
  
 
  
 
  
 
   
   
    myRequest.method = URLRequestMethod.POST;  


  
  
  
  
 
  
 
  
 
   
   
    myRequest.data = saveZIP ( Method.LOCAL );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    navigateToURL ( myRequest, "_blank" );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    return null;  


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    private function unixToDos( pTimeStamp:Number ):Number  


  
  
  
  
 
  
 
  
 
   
   
    {  


  
  
  
  
 
  
 
  
 
   
   
    var currentDate:Date = new Date ( pTimeStamp );  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    if ( currentDate.getFullYear() < 1980 ) currentDate = new Date (1980, 1, 1, 0, 0, 0);  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    return ( (currentDate.getFullYear() - 1980) << 25) | (currentDate.getMonth() << 21) | (currentDate.getDate() << 16) |  


  
  
  
  
 
  
 
  
 
   
   
    (currentDate.getHours() << 11) | (currentDate.getMinutes() << 5) | (currentDate.getSeconds() >> 1);  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    }  


  
  
  
  
 
  
 
  
 
   
   
      


  
  
  
  
 
  
 
  
 
   
   
    }  


 
 
 
 

 

 

  
  
  

使用方法是复制以上代码,保存为ASZip.as,然后下载http://code.google.com/p/aszip/downloads/list 解压ASZip 0.2版本后,把保存的ASZip.as直接覆盖到org/aszip/zip 目录下,即可使用。

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Java修道之路,问鼎巅峰,我辈代码修仙法力齐天
<center<fontcolor00FF7Fsize5face"黑体"代码尽头谁为峰,一见秃头道成空。</font<center<fontcolor00FF00size5face"黑体"编程修真路破折,一步一劫渡飞升。</font众所周知,编程修真有八大境界:1.Javase练气筑基2.数据库结丹3.web前端元婴4.Jav
浩浩 浩浩
3年前
【Flutter实战】图片和Icon
3.5图片及ICON3.5.1图片Flutter中,我们可以通过Image组件来加载并显示图片,Image的数据源可以是asset、文件、内存以及网络。ImageProviderImageProvider是一个抽象类,主要定义了图片数据获取的接口load(),从不同的数据源获取图片需要实现不同的ImageProvi
Wesley13 Wesley13
3年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Stella981 Stella981
3年前
Android So动态加载 优雅实现与原理分析
背景:漫品Android客户端集成适配转换功能(基于目标识别(So库35M)和人脸识别库(5M)),导致apk体积50M左右,为优化客户端体验,决定实现So文件动态加载.!(https://oscimg.oschina.net/oscnet/00d1ff90e4b34869664fef59e3ec3fdd20b.png)点击上方“蓝字”关注我
Wesley13 Wesley13
3年前
Java多线程导致的的一个事物性问题
业务场景我们现在有一个类似于文件上传的功能,各个子站点接受业务,业务上传文件,各个子站点的文件需要提交到总站点保存,文件是按批次提交到总站点的,也就是说,一个批次下面约有几百个文件。      考虑到白天提交这么多文件会影响到子站点其他系统带宽,我们将分站点的文件提交到总站点这个操作过程独立出来,放到晚上来做,具体时间是晚上7:00到早上7:00。
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这