www.digitalmars.com         C & C++   DMDScript  

D - help with std.zip

reply Ant <duitoolkit yahoo.ca> writes:
How to add new members to an existing ZipArchive?
I just read the file,
create the ZipArchive instance from the file
add the new member
build the archive
and write it back to a file

All the previous members became 0 length
(can be listed but unzip does not create any files)

Am I missing something?

any idea? thanks.

Ant
Mar 15 2004
next sibling parent "Matthew" <matthew stlsoft.org> writes:
I was just trying to use it myself, but because I'm in a rush I've resorted
to using Ruby.

Anyone have a couple of simple std.zlib samples they would like to post?


"Ant" <duitoolkit yahoo.ca> wrote in message
news:pan.2004.03.16.03.12.06.886848 yahoo.ca...
 How to add new members to an existing ZipArchive?
 I just read the file,
 create the ZipArchive instance from the file
 add the new member
 build the archive
 and write it back to a file

 All the previous members became 0 length
 (can be listed but unzip does not create any files)

 Am I missing something?

 any idea? thanks.

 Ant

Mar 16 2004
prev sibling parent reply =?ISO-8859-1?Q?Julio_Jim=E9nez?= <jujibo inicia.es> writes:
Ant wrote:
 How to add new members to an existing ZipArchive?
 I just read the file,
 create the ZipArchive instance from the file
 add the new member
 build the archive
 and write it back to a file
 
 All the previous members became 0 length
 (can be listed but unzip does not create any files)
 
 Am I missing something?
 
 any idea? thanks.
 
 Ant
 

I think you can't in that way. You must create a ZipArchive object with the zip file you want to open... then can get the ArchiveMember from directory member, defined: (ArchiveMember[char[]] directory;) Create a New ZipArchive object and add this ArchiveMember plus the files you want... then delete de old zip file and rename the new one created But I think there is something wrong in std.zip module regards Julio
Mar 16 2004
parent reply =?ISO-8859-1?Q?Julio_Jim=E9nez?= <jujibo inicia.es> writes:
Julio Jiménez wrote:
 Ant wrote:
 

 I think you can't in that way.
 
 You must create a ZipArchive object with the zip file you want to open...
 then can get the ArchiveMember from directory member, defined:
  (ArchiveMember[char[]] directory;)
 Create a New ZipArchive object and add this ArchiveMember plus the files 
 you want... then delete de old zip file and rename the new one created
 
 But I think there is something wrong in std.zip module
 
 
 regards
 
 
 Julio
 

Sorry... yes... you can a little example: // Program for testing zlib // Modified to append a file to a existing zipfile... import std.file; import std.date; import std.zip; import std.zlib; int main(char[][] args) { byte[] buffer; std.zip.ZipArchive zr; char[] zipname; ubyte[] data; testzlib(); if (args.length > 1) zipname = args[1]; else zipname = "test.zip"; buffer = cast(byte[])std.file.read(zipname); zr = new std.zip.ZipArchive(cast(void[])buffer); printf("comment = '%.*s'\n", zr.comment); //zr.print(); foreach (ArchiveMember de; zr.directory) { printf("date = '%.*s'\n", std.date.toString(std.date.toDtime(de.time))); //data = zr.expand(de); } printf("**Success**\n"); ArchiveMember am = new ArchiveMember(); am.compressionMethod = 8; am.name = "foo2.bar"; // name for your new archive to append am.time = toDosFileTime(getUTCtime()); //am.extra = cast(ubyte[])"ExTrA"; am.expandedData = cast(ubyte[])"We all live in a yellow submarine, a yellow submarine"; am.expandedSize = am.expandedData.length; zr.addMember(am); void[] data2 = zr.build(); // build new zip file std.file.write(zipname, cast(byte[])data2); // overwrite the old file with new data return 0; } void arrayPrint(ubyte[] array) { //printf("array %p,%d\n", (void*)array, array.length); for (int i = 0; i < array.length; i++) { printf("%02x ", array[i]); if (((i + 1) & 15) == 0) printf("\n"); } printf("\n\n"); } void testzlib() { ubyte[] src = cast(ubyte[]) "the quick brown fox jumps over the lazy dog\r the quick brown fox jumps over the lazy dog\r "; ubyte[] dst; arrayPrint(src); dst = cast(ubyte[])std.zlib.compress(cast(void[])src); arrayPrint(dst); src = cast(ubyte[])std.zlib.uncompress(cast(void[])dst); arrayPrint(src); } but it create a corrupted zip file.... try to test it, its a begining... :-) i only had 5 minutes to test... later Julio
Mar 16 2004
parent Ant <duitoolkit yahoo.ca> writes:
On Tue, 16 Mar 2004 11:52:30 +0100, Julio Jiménez wrote:

 Julio Jiménez wrote:
 Ant wrote:
 

 I think you can't in that way.
 
 You must create a ZipArchive object with the zip file you want to open...
 then can get the ArchiveMember from directory member, defined:
  (ArchiveMember[char[]] directory;)
 Create a New ZipArchive object and add this ArchiveMember plus the files 
 you want... then delete de old zip file and rename the new one created
 
 But I think there is something wrong in std.zip module


I think you're right. Anyone has experience witht the zip module? Ant
Mar 16 2004