dimanche 22 novembre 2015

zip file contents have no data

I have for a while been trying to make a zipping script. The closest I have come to what I am needing is this one.

import flash.filesystem.File;
import flash.events.Event;
import FZIP.*;

var directory:File = File.desktopDirectory.resolvePath("Test File");

var zip:FZip = new FZip(); 
var files:Array = directory.getDirectoryListing();
for(var i:uint = 0; i < files.length; i++)
{
var file_2:File = new File(files[i].nativePath);
//  zip.addFile(file_2.name, file_2.data);
zip.addFile(file_2.name, ba);
trace(file_2.name);
trace(files[i].nativePath);
trace(file_2.data);
trace(file_2.size);
}

var ba:ByteArray = new ByteArray(); 
zip.serialize(ba); 
ba.position = 0; 
var finalZIP:File = File.desktopDirectory.resolvePath("TEST.zip"); 
var fs:FileStream = new FileStream(); 
fs.open(finalZIP, FileMode.WRITE); 
fs.writeBytes(ba); 
trace("BA POS: "+ba.position);
fs.close();

The problem is that all files are without data (have no size).

Aucun commentaire:

Enregistrer un commentaire