Samir Sabri
Samir Sabri

Reputation: 977

zipping files or a folder into a zip file?

I need to know, how to compress files into a zip file? I found this beautiful gist, it will unzip a zip file.

I found haxe.zip.Compress but, I didn't find any example about using it, can some please help me in compressing files in haxe?

EDIT

Thanks to answer below, I tried Entry:

    var fileInput:FileInput = File.read("myfile.xml");
    var bytes:Bytes = Bytes.ofData(File.getBytes("myfile.xml").getData());

    var entry:Entry = {
        fileName:"myfile.xml", 
        fileSize:bytes.length,
        fileTime:Date.now(),
        compressed: false,
        dataSize: 0,
        data: bytes,
        crc32:Crc32.make(bytes)
        };

Tools.compress(entry, 1); 

But I found that Tools.compress is not implemented for PHP

I tried:

Compress.run(bytes, 1);

I got:

uncaught exception: Not implemented for this platform

Called from haxe.zip.Compress::run
Called from Main::main

Although Compress is mentioned as Available on all platforms

Any idea?

Upvotes: 3

Views: 697

Answers (2)

Mark Knol
Mark Knol

Reputation: 10163

I though that the haxe.zip package only worked for neko target, not sure. If so, you may need the format library.

Upvotes: 0

Jonas Malaco
Jonas Malaco

Reputation: 1557

An equivalent complete gist would take me some time (and I would have to make sure that everything is working properly), but the direction you should follow is...

You'll need to create an uncompressed Entry for each file, compress it with haxe.zip.Tools.compress and finally write all entries (List<Entry>) with haxe.zip.Writer.write.

Upvotes: 2

Related Questions